SantoshNarayan
Technical User
The following code is in error. How can I pass generic class objects to
non-member routines ? The compile time errors are :
1. Undefined symbol 'mytype'.
2. Cannot generate template specialization myclass<mytype>.
3. Undefined symbol 'myclass'.
These errors are fired at the point where the function has been defined.
#include <iostream>
using namespace std;
template <typename mytype> class myclass
{
mytype val;
public :
myclass(mytype i){ val = i; }
mytype func(){ return val; }
friend void outfunc(myclass<mytype> &obj);
};
void outfunc(myclass<mytype> &obj)
{
cout << obj.val << endl;
}
int main()
{
myclass<int> ext(11);
cout << ext.func() << endl;
outfunc(ext);
return 0;
}
non-member routines ? The compile time errors are :
1. Undefined symbol 'mytype'.
2. Cannot generate template specialization myclass<mytype>.
3. Undefined symbol 'myclass'.
These errors are fired at the point where the function has been defined.
#include <iostream>
using namespace std;
template <typename mytype> class myclass
{
mytype val;
public :
myclass(mytype i){ val = i; }
mytype func(){ return val; }
friend void outfunc(myclass<mytype> &obj);
};
void outfunc(myclass<mytype> &obj)
{
cout << obj.val << endl;
}
int main()
{
myclass<int> ext(11);
cout << ext.func() << endl;
outfunc(ext);
return 0;
}