Archived

This topic is now archived and is closed to further replies.

mail_man

g++ template friend function

Recommended Posts

Can anyone help me with this problem that I seem to be having with the g++ complier. I know it is the complier because it works fine with the cxx complier. I want to create a operator<< overloader for a templatized class I have created. However, I can''t seem to instantiate it right. The g++ FAQ tells me to use this, but it still doesn''t compile, just gets rid of the non-template warnings friend ostream& opeator<< <> (ostream &, foo); Where T is the class template type. I used an instantiation file for the class, but what do I need for the friend functions? Any help would be appreciated.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Here''s some code I prepared earlier...this works with egcs and gcc-2.95.x, and probably others.

template
class smart_ptr {
// ... yada yada ...

friend ostream &operator << <> (ostream &out, smart_ptr const &o);
};

template
ostream &operator << (ostream &out, smart_ptr const &o) {
out << *(o.ref->t);
return out;
}

Share this post


Link to post
Share on other sites
Hmmmm, take two, without the formatting problems (hopefully)...

Here''s some code I prepared earlier...this works with egcs and gcc-2.95.x, and probably others.

template <typename T>
class smart_ptr {
// ... yada yada ...

friend ostream &operator << <> (ostream &out, smart_ptr<T> const &o);
};

template <typename T>
ostream &operator << (ostream &out, smart_ptr<T> const &o) {
out << *(o.ref->t);
return out;
}

Share this post


Link to post
Share on other sites