首页 > 解决方案 > 在 VS 2005 中获取编译器错误'二进制'<<':找不到运算符'

问题描述

构建项目时出现以下编译器错误:

XMLHelper.h(22) : 错误 C2678: 二进制 '<<' : 未找到采用 'COSB::AnyException' 类型的左侧操作数的运算符(或没有可接受的转换)

XMLHelper.h 的代码:

 class XMLException : public COSB::Exception

{
public:
    XMLException(const MSXML2::IXMLDOMParseErrorPtr &verr, const char *prefix_description="XML error")
        : Exception(verr->errorCode)
    {
/*line 22  error line */
*this << prefix_description << " " << std::hex << long(verr->errorCode) << std::dec;
   ...} 

XMLHelper.h 不直接属于我的项目。我检查了具有以下函数定义的 exception.h:

class ExceptionBase : public std::exception
{ ...}

// Any exception including Win32 structured exceptions and COSB::Exception.
class AnyException: public ExceptionBase
{
public:

  // This insertion operator needed to be declared as a member function or the 
  //compiler gets confused as to which template function to apply.
     // Notice that stateful stream manipulators like width will probably not 
  //work

AnyException &operator<<( std::ostream& (_cdecl *f)(std::ostream&) )
{
    ExceptionBufferStream buf(FormatHolder());
    (*f)(buf);
    AppendToDescription(buf.c_str(),buf.LineSize());
    return  *this;
    }
   ..}

如何解决此错误?

谢谢拉古

标签: c++xmlexceptiontype-conversionoperator-overloading

解决方案


推荐阅读