我有一个使用Visual Studio 2008 C++开发的工程,其中包含一个模板类。该模板类在构造函数中采用模板化值,例如:
template< typename A >
struct Foo
{
const A& a_;
Foo( const A& a ) : a_( a ) { };
};
因此,我必须像这样构建这个类:
int myval = 0;
Foo< int > foo( myval );
当在构造函数中已经指定了int
时,需要再次指定int
作为模板参数似乎是多余的。我希望能以这种方式使用它:
Foo foo( myval );
现在我得到编译器错误:
error C2955: 'Foo' : use of class template requires template argument list
感谢您,PaulH。