|
-
November 30th, 2004, 12:38 AM
#1
template and friend ostream operator problem, please help
I'm currently trying to convert a class into a template but am having problems with the overloaded ostream operator and the templates. I have the overloaded ostream function as a friend inside a class called AssocArray, I have tried everything that I can think of to get this function working as a template but it is being stubborn. I have uploaded a copy of the erros I'm recieving along with the code that portion of the code that is giving me trouble to a html file on the web to make things easy for everyone. Any help you could provide would be much appreciated.
All the code and erros are here:
http://bsdadmins.net/problems.html
Dav
-
November 30th, 2004, 12:57 AM
#2
Re: template and friend ostream operator problem, please help
In AssocArray.h, you need to indicate that the operator<< function is a template function. This is done by placing "<>" after the function name, as follows:
Code:
template <class T1, class T2>
class AssocArray {
friend ostream& operator<< <> (ostream& s, const AssocArray<T1, T2> &);
//... etc
This will at least fix some of the warnings (AssocArray.h:17), but I'm not sure about the others.
Try it and see what you get.
Just remember that it is always darkest just before it goes pitch black.
-
November 30th, 2004, 02:50 PM
#3
Re: template and friend ostream operator problem, please help
If you're template class needs to be access by other *.cpp files, then you need to move the template class implementation into your header file.
I recommend you also move the implementation of your friend operator inside the class declaration.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|