Template constructor in a class template - how to explicitly specify template argument for the 2nd parameter?
compile error when tried to explicit specify template
You can't explicitly specify the template arguments for a constructor, because the constructor has no name on its own, and so there's no syntax for it.
But, you can ensure that correct template arguments are inferred, by
casting actual arguments, and/or
introducing "artificial" extra arguments just to carry type information, if necessary, and/or
use a factory function.
For example, you can define
template< class Type > struct TypeCarrier{ typedef Type T; };
struct MyClass
{
template< class Type >
MyClass( TypeCarrier< Type > ) { ... }
};
...
MyClass o( TypeCarrier() );
But don't get carried away with such techniques.
Instead, if the apparent need to explicitly specify constructor template arguments pops up, think about whether the design is really sound?
Perhaps you can use some simpler design if you reflect on what it’s for?