Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Generic class objects to non-member routines ? How to ?

Status
Not open for further replies.

SantoshNarayan

Technical User
Jun 6, 2001
13
IN
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;
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top