Qtには、そのように呼び出される優れたデバッグ機能があります
qDebug() << first_qobject << second_qobject;
オブジェクトの「標準to-string」を含む行を生成し、-そしてそれが重要な部分です-を出力し、\n
後に蒸気をフラッシュしsecond_object
ます。std::string to_string()
すべてのクラスに私が呼び出すメソッドがあるという規則によって、その動作を再現したいと思います。
struct myDebug{
template<typename T>
myDebug& operator<<(T t){
std::cout << t.to_string() << " "; // space-separated
return *this;
}
};
struct Point{
std::string to_string(){ return "42"; }
};
myDebug() << Point() << Point(); // should produce "42 42" plus a newline (which it doesn't)
私の質問は次のとおりです*this
。2回目に戻った後、返されたオブジェクトが呼び出されなくなったことを確認する方法はありますか? std::endl
?を印刷できるように qDebug()
それができるようです。