Is it possible to have a templated constructor with a template parameter that is explicitly specified (as opposed to deduced)? Something like this: Code: struct A { template A(int x) { } }; int main() { A a = A(5); } This code fails to compile, which is not surprising because A(5) is the syntax for when the template parameter belongs to the class, not the constructor. If this simply cannot be done, then is there a way to achieve a similar effect?
I am not sure if it can be done, as trying A::A<float>(5) does not work either. Why exactly do you want to do this? You may be able to use the named constructor idiom, i.e., provide a static member function template that acts as a constructor, returning an object of the class.