Jump to content
  • Advertisement

Archived

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

mail_man

g++ template friend function

This topic is 6361 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!