>> 演算子をオーバーロードして、クラスで cin のように使用しようとしています。コードは次のとおりです。
class Base {
public:
int mx;
Base() {}
Base(int x) : mx(x) {}
friend std::istream &operator>>(std::istream &, Base &);
friend std::ostream &operator<<(std::ostream &, const Base &);
};
std::istream &operator >>(std::istream &in, Base &object) {
in >> object.mx;
return in;
}
std::ostream &operator <<(std::ostream &out, const Base &object) {
out << object.mx;
return out;
}
int main() {
Base test();
std::cin >> test;
std::cout << test;
system("PAUSE");
return 0;
}
コンパイルしようとすると、「エラー C2679: バイナリ '>>' : タイプ 'Base (__cdecl *)(void)' の右側のオペランドを取る演算子が見つかりません (または許容できる変換がありません)」と Intellisense が表示されますこれらのオペランドに一致する演算子「>>」はありません。
ostream バージョンには問題がないようです。
なんで?