Jump to content
  • Advertisement

Archived

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

fraKtal

Are your friends efficient?

This topic is 5361 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

I was just reading a book (C++ How To Program 4th Ed. by the Deitel ppl) for class, and in it it says when you overload opperators, and you don''t make them class members, you should make them friends of that class, because they are more efficient. my question is why? Maybe I''m missing something, but that''s why I posting here isn''t it?

Share this post


Link to post
Share on other sites
Advertisement
I see no reason why member functions would be less efficient than friend functions.
An advantage of having common operations (operators) as friend functions is that the class-type argument can be implicitly converted when the user calls the operator/function, and that the classtype does not have to be the first argument (X operator+(int, const X&).

Marijn

Share this post


Link to post
Share on other sites
that is the most ridiculous thing I''ve heard all day (yes, it''s morning, I know, but still...)

The friend keyword is a language feature. That''s all.

There''s an article on the C++ User''s Journal (www.cuj.com) that explains why non-friend, non-member overloaded operators actually increase encapsulation.

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!