Archived

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

Are your friends efficient?

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