C++相談室 part41
■ このスレッドは過去ログ倉庫に格納されています
0674デフォルトの名無しさん
2005/08/03(水) 16:15:06std::ostream& operator<< (std::ostream& os, const B& b) { return os << b.member; }
これで、
B b; std::cout << b << std::endl;
が通る。
このベースクラスBを派生すると
struct D : public B {};
D d; std::cout << d << std::endl; // エラー
コンパイルできない。
ベースクラス用のoperator<<()を呼び出すような実装をするとき、
std::ostream& operator<< (std::ostream& os, const D& d) { この部分; }
に何を書けばいいのか教えてください。
■ このスレッドは過去ログ倉庫に格納されています