   [C++] Equality operator overloading: friend member functions
  According to this page, the following code should compile perfectly fine:template <typename T>class Vector{public:    friend bool operator==<T> (const Vector<T> &v1, const Vector<T> &v2);};template <typename T>inlinebool operator==(const Vector<T> &v1, const Vector<T> &v2){}However, GCC 4.4.0 complains right at the declaration:D:\C\Performance\main.cpp:19: error: declaration of 'operator==' as non-functionD:\C\Performance\main.cpp:19: error: expected ';' before '<' tokenWhy does this not work? Must I use a new template parameter just for the function?Also, should all equality / inequality / shift operators be defined as friend "symmetric" functions rather then "asymmetric" member functions? Are there exceptions?Thank you!   
Quote:Original post by DecriusAccording to this page, the following code should compile perfectly fine:*** Source Snippet Removed ***However, GCC 4.4.0 complains right at the declaration:D:\C\Performance\main.cpp:19: error: declaration of 'operator==' as non-functionD:\C\Performance\main.cpp:19: error: expected ';' before '<' tokenWhy does this not work? Must I use a new template parameter just for the function?Did you forward declare the Vector class template and the operator==() function?   ;Quote:Original post by jykQuote:Original post by DecriusAccording to this page, the following code should compile perfectly fine:*** Source Snippet Removed ***However, GCC 4.4.0 complains right at the declaration:D:\C\Performance\main.cpp:19: error: declaration of 'operator==' as non-functionD:\C\Performance\main.cpp:19: error: expected ';' before '<' tokenWhy does this not work? Must I use a new template parameter just for the function?Did you forward declare the Vector class template and the operator==() function?Oh, that's really silly...(A)The other question remains though :)   ;Quote:Original post by DecriusAlso, should all equality / inequality / shift operators be defined as friend "symmetric" functions rather then "asymmetric" member functions? Are there exceptions?Generally, I would say yes.  This allows implicit conversions (via constructor or conversion operator) for the left hand argument, just as with the right hand side.  Consider:const char* cstring = "foo";std::string cppstring = "bar";std::string a = cppstring + cstring; // works always, uses std::string::string (const char*)std::string b = cstring + cppstring; // won't work unless operator+ is "symmetric"Not all operators can be done this way (e.g. assignment operators), so obviously those are out, but it generally can't hurt where it's possible.EDIT:  Also, I should share this cheap trick:template <typename T>class Vector{public:    friend bool operator==(const Vector<T> &v1, const Vector<T> &v2) {   ...    }};Also works [lol]   ;template <typename T>class Vector{    friend bool operator==<T> (const Vector<T> &v1, const Vector<T> &v2);    public:    private:    };template <typename T>inlinebool operator==(const Vector<T> &v1, const Vector<T> &v2){}...is better to convey the notion that friendship has nothing to do with accessibility in a class.