在类中使用函数模板,这个程序有什么问题。
#include "stdafx.h"
#include <iostream.h>
class CProperty{
public:
CProperty(){
}
template <class T>
T getValue(){
return _value;
}
template <class T>
void setValue( T _value){
value = _value;
}
template <class T> T _value;
};
main()
{
CProperty p;
p.setValue( (int)512 );
int i = p.getValue();
return 0;
}
编译错误:
C:\test\test6\test6.cpp(51) : error C2783: 'T __thiscall CProperty::getValue(void)' : could not deduce template argument for 'T'
大家也看出来,我想干什么了。
怎么解决这个问题呢?
谢谢?