C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Placement of overloaded operators

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Dag-Erling Smørgrav
Guest





PostPosted: Tue Dec 16, 2008 6:27 pm    Post subject: Placement of overloaded operators Reply with quote



{ FAQ section 13 explains many aspects of operator overloading. -mod }

What, if any, is the difference between defining an overloaded operator
as a member of a class, and defining it as a global function?

For instance, in the GNU STL (derived from HP / SGI), the equality
comparison for std::vector is defined as follows:

template<typename _Tp, typename _Alloc>
inline bool
operator==(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
{ return (__x.size() == __y.size()
&& std::equal(__x.begin(), __x.end(), __y.begin())); }

Could it not have been defined as

inline bool
operator==(const vector<_Tp, _Alloc>& __other)
{ return (size() == __other.size()
&& std::equal(begin(), end(), __other.begin())); }

within template<_Tp, _Alloc> class vector { } intead?

DES
--
Dag-Erling Smørgrav - des (AT) des (DOT) no

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
 


Powered by phpBB © 2001, 2006 phpBB Group