VC6和模板错误
我正在重载运算符<<为类实现类似接口的流:
template<typename T>
CAudit& operator << ( const T& data ) {
audittext << data;
return *this;
}
CAudit& operator << ( LPCSTR data ) {
audittext << data;
return *this;
}
模板版本无法使用“致命错误C1001:INTERNAL COMPILER ERROR(编译器文件'msc1.cpp',第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;
};
运算符的函数重载&lt;&lt;&lt;&lt;&lt;&lt;用于允许write()用作流操纵器:
CAudit audit
audit << "Billy" << write;
没有找到相关结果
已邀请:
4 个回复
钨蜡唤喉晤
稳赣苍卯改
这里的希望是第一次查找
找到单个成员模板。其他
候选人不是其他课程和内置插入的成员。他们应该明白这个模板更糟糕。你
里面的第二次查询只需要处理叫
的
成员。
壬驴拿歪竞
编辑:
社攻取墟槽
你能发布更多代码吗?