Is it possible to mix constructors with fixed parameters and constructor templates?
My Code:
#include <iostream>
class Test {
public:
Test(std::string, int, float) {
std::cout << "normal constructor!" << std::endl;
}
template<typename ... Tn>
Test(Tn ... args) {
std::cout << "template constructor!" << std::endl;
}
};
int main() {
Test t("Hello World!", 42, 0.07f);
return 0;
}
This gives me "template constructor!". Is there a way, that my normal constructor is called?
Sure, in the event of two equally good matches, the non-template is preferred:
Test t(std::string("Hello"), 42, 0.07f);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With