class Node {
public:
template<class T> T* GetComponent() {
return new T(this); // actual code is more complicated!
}
Transform* Transform() {
return this->GetComponent<Transform>(); // invalid template argument for 'T', type expected
}
};
But calling same method works from another place! like main().
What is wrong with this code!!!
The code you provided has typos, as already have been mention. After fixing them you’ll get the error you mentioned.
The reason why you get it is that you have a member function with a name
Transform, same as the type you want to concretiseGetComponentfor. So, the solution is to “help” complier by using full type name, including namespace. This assumes thatTransformis defined in a global namespace:Use this if you have defined it in a namespace:
EDIT: the full code I used: