g++ template friend function

Started by
1 comment, last by mail_man 23 years ago
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.
Advertisement
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;
}
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;
}

This topic is closed to new replies.

Advertisement