2
有誰知道如何讓這兩個重載運營商共存?全球運營商<<和成員運營商之間的共存<<
#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
{
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);
錯誤:
$ g++ prov.cpp -o prov
prov.cpp:13:33: error: declaration of ‘operator<<’ as non-function
prov.cpp:13:33: error: expected ‘;’ at end of member declaration
prov.cpp:13:36: error: expected unqualified-id before ‘<’ token
我爲我的英語不好對不起。基於這個原因,我寫的很少。
問候和感謝!
呃,什麼都不做? – 2013-05-02 13:34:05
您是否遇到錯誤? – Collin 2013-05-02 13:36:33
g ++ version 4.7.3 編譯器拋出此錯誤: prov.cpp:13:33:錯誤:將'operator <<'聲明爲非函數 prov.cpp:13:33:error:expected';'at成員聲明的末尾 prov.cpp:13:36:錯誤:預期的'<'token'之前的非限定id – xgbuils 2013-05-02 13:58:12