Is there a way to have the compile deduce the template parameter automatically?
template<class T> struct TestA { TestA(T v) {} }; template<class T> void TestB(T v) { } int main() { TestB (5); }
Test B works fine, however when i change it to TestA it will not compile with the error ‘ use of class template requires template argument list’
No, there isn’t. Class templates are never deduced. The usual pattern is to have a
make_free function:See
std::pairandstd::make_pair, for example.In C++0x you will be able to do
to avoid having to specify the type for local variables.