クラスのインターフェイスのようなストリームを実装するために、演算子 << をオーバーロードしています。
template<typename T>
CAudit& operator << ( const T& data ) {
audittext << data;
return *this;
}
CAudit& operator << ( LPCSTR data ) {
audittext << data;
return *this;
}
テンプレート バージョンは、「致命的なエラー C1001: INTERNAL COMPILER ERROR (compiler file 'msc1.cpp', line 1794)」でコンパイルに失敗します。非テンプレート関数はすべて正しくコンパイルされます。
これは、テンプレートを処理する際の VC6 の欠陥によるものですか? これを回避する方法はありますか?
ありがとう、パトリック
編集 :
完全なクラスは次のとおりです。
class CAudit
{
public:
/* TODO_DEBUG : doesn't build!
template<typename T>
CAudit& operator << ( const T& data ) {
audittext << data;
return *this;
}*/
~CAudit() { write(); }//If anything available to audit write it here
CAudit& operator << ( LPCSTR data ) {
audittext << data;
return *this;
}
//overload the << operator to allow function ptrs on rhs, allows "audit << data << CAudit::write;"
CAudit& operator << (CAudit & (*func)(CAudit &))
{
return func(*this);
}
void write() {
}
//write() is a manipulator type func, "audit << data << CAudit::write;" will call this function
static CAudit& write(CAudit& audit) {
audit.write();
return audit;
}
private:
std::stringstream audittext;
};
この問題は、write() をストリーム マニピュレータとして使用できるようにするために使用される operator << の関数オーバーロードで発生します。
CAudit audit
audit << "Billy" << write;