c++ - Coexistence among global operator<< and member operator<< -
does know how make these 2 overloaded operators coexist?
#include<iostream> template< typename t > class a; template< typename t > std::ostream& operator<<( std::ostream& o, const a<t>& e ); template< typename t > class { a& operator <<( const a& e ); friend std::ostream& operator<< <>( std::ostream& o, const a<t>& e ); }; int main() { // program return 0; } // def a<t>::a& a::operator <<( const a& e ); // def std::ostream& operator<< <>( std::ostream& o, const a<t>& e );
error:
$ g++ prov.cpp -o prov prov.cpp:13:33: error: declaration of ‘operator<<’ non-function prov.cpp:13:33: error: expected ‘;’ @ end of member declaration prov.cpp:13:36: error: expected unqualified-id before ‘<’ token
i’m sorry bad english. reason write little.
greeting , thanks!
i think want:
friend std::ostream& operator<< <t>( ... );
in friend declaration. (i'm not sure: policy has been define friend inline
, didn't matter if template or not. looks examples in standard.)
Comments
Post a Comment