【发布时间】:2010-09-06 17:22:47
【问题描述】:
我在将方法的参数作为模板返回时遇到了一些问题,请看:
// CTestClass.h
template<class T>
class CTestClass
{
public:
T getNewValue();
};
// CTestClass.cpp
template<class T>
T CTestClass<T>::getNewValue()
{
return 10; // just for tests I'm returning hard coded 10
}
// main.cpp
int _tmain(int argc, _TCHAR* argv[])
{
CTestClass<int> s;
int a = s.getNewValue();
return 0;
}
我收到以下错误:
错误 LNK2019:函数 _wmain 中引用了无法解析的外部符号“public: int __thiscall CTestClass::getNewValue(void)”(?getNewValue@?$CTestClass@H@@QAEHXZ)
【问题讨论】:
标签: c++ templates return-value