我試圖寫一個簡單的審計類,通過操作< <需要輸入和接收定製的機械手這樣以後寫審計:定製的流處理器爲
class CAudit
{
public:
//needs to be templated
CAudit& operator << (LPCSTR data) {
audittext << data;
return *this;
}
//attempted manipulator
static CAudit& write(CAudit& audit) {
//write contents of audittext to audit and clear it
return audit;
}
private:
std::stringstream audittext;
};
//to be used like
CAudit audit;
audit << "Data " << data << " received at " << time << CAudit::write;
我認識到,重載運營商我的代碼沒有返回流對象,但想知道是否仍然可以使用像句法這樣的操縱符。目前,編譯器將'< <'視爲二進制右移運算符。
感謝您的任何輸入, 帕特里克
謝謝,最後打造 – Patrick 2009-08-25 14:51:10