I have a class exactly as below.
But I get errors when declaring pointer var to my class. What's happening here? There are some similar questions here but I couldn't understand why my case is not working as the pointer is of the class itself.
code:
#include<iostream>
template <class T>
class A;
int main ()
{
A* objA = NULL;
objA = new A();
objA->foo("some string");
delete objA;
objA = NULL;
return 0;
}
template <class T>
class A
{
void foo(T);
};
template <class T>
void A<T>::foo(T str)
{
std::cout << str << "\n";
}
Aucun commentaire:
Enregistrer un commentaire