掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
テンプレート引数にstd::endlを渡す (ID:66731)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
以下のようなDebugクラスを作成したのですが、 Debug::operator<<にstd::endlを渡すとコンパイルエラーになります。 どのように修正したらよいでしょうか? #include <iostream> using namespace std; class Debug { public: template <class T> Debug& operator<<(const T& a) { // デバッグ時のみ std::cout << a を実行する std::cout << a; } }; int main() { Debug d; d << "foo" << 100 << '\n'; // 問題なし d << std::endl; // コンパイルエラー } コンパイルエラーメッセージ: no match for 'operator<<' in 'd << std::endl' g++ 3.4.4 cygwin
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.