I have a problem when use the templates with a method parameter inside a class.
The following is an example but not my real code which has the problem, in order to simplify the code.
Class declaration:
class Test {
public:
Test();
template <class T>
void PrintData(T info);
};
Class definition:
Test::Test(){}
void Test::PrintData(T info){
cout << info << endl;
}
When usage:
int main(){
Test test;
test.PrintData<const char*>("Thank you.");
return 0;
}
The error messages:
- variable or field 'PrintData' declared void
- 'T' was not declared in this scope
What is the problem in my code, and/or how to use the templates with the method parameter correctly ?