 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Dag-Erling Smørgrav Guest
|
Posted: Tue Dec 16, 2008 6:27 pm Post subject: Placement of overloaded operators |
|
|
{ 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 |
|
 |
Powered by phpBB © 2001, 2006 phpBB Group
|