I have a class with 2 constructors.
explicit MyClass(size_t num);
template<class T> MyClass(T myObj);
And I want that whenever I make
MyClass obj( 30 );
The first constructor will be called,
And on implicit constructors and
MyClass obj = 30;
The second ctor will be called.
How can I make it happen?
30 is a signed integer value, so it doesn’t exactly fit the signature of your first constructor (therefore, the template gets instantiated).
You can either change the signature of the explicit constructor to accept an
int, and thanMyclass obj( 30 );will call the explicit constructor, or call it with30uso that you match the explicit signature.