Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
関数に渡すストリームの種類に応じて、画面に出力したりファイルに書き込んだりできるように、クラスに関する情報を表示する関数を変更したいと思います。
次のような機能が欲しいのですが。
void output(int x, default (what class do I need here??) &stream=cout){ stream << x ; }
それを行うための適切な方法は何ですか?助けてくれてありがとう!
あなたは一般的に欲しいですstd::ostream&。ほとんどのプログラマーは、あなたが行ったようにoperator<<別の関数を定義するのではなく、単にオーバーロードすることに注意してください。output()
std::ostream&
operator<<
output()