【发布时间】:2011-10-12 10:45:05
【问题描述】:
鉴于此代码:
class X
{
public:
template< typename T >
void func( const T & v );
};
template<>
void X::func< int >( const int & v )
{
}
template<>
void X::func< char * >( const char * & v ) // 16
{
}
当我编译它时,我得到以下错误。
test.cpp:16: error: template-id 'func<char*>' for 'void X::func(const char*&)' does not match any template declaration
任何人都可以对此有所了解吗?
【问题讨论】:
-
如果你不打算实现
template<typename T> void X::func (const T & t) { ... },你可以只使用为int和char*参数重载的成员函数。
标签: c++ templates template-specialization