我正在尝试在模板之外声明一个成员函数 - GetValue。
我收到错误: main.cpp|16|错误:“GenericType Test::GetValue()”的重新定义| |错误:'GenericType Test::GetValue()' 先前在此处声明|
#include <iostream>
template <class GenericType>
class Test {
public:
GenericType x;
Test(){ }
Test(int y) : x( y){ }
GenericType GetValue(){}
};
template <class GenericType>
GenericType Test<GenericType>::GetValue(){
return x;
}
int main()
{
Test<int> y(5);
std::cout << y.GetValue();
return 0;
}
最佳答案
改变成员函数定义
GenericType GetValue(){}
成员函数声明
GenericType GetValue();
关于c++ - 我的成员模板函数声明有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18875726/