在C ++代码中出现歧义错误

时间:2012-04-24 12:41:28

标签: c++ overloading

我们从RogueWave的RWCString类派生了我们自己的Utility String类。派生类通过<<>>运算符处理数字到字符串的转换。

以下是此课程的声明。

#ifndef UtlString_h
#define UtlString_h 1
#include "platform.h"

#ifdef WIN32
#include "Utilities.h"
#endif

#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include "rw/cstring.h"
#include "UtlIdentifier.h"

const troint64 BIGBUF_LEN = 56000L ;

class UtlString;
unsigned UtlExport gHashString (const UtlString &);


class  UtlExport UtlString : public RWCString  
{
  public:
      UtlString ();
      UtlString (char c);
      UtlString (char c, size_t N);
      explicit UtlString (const char* cs);
      UtlString (const char *cs, size_t N);
      UtlString (const RWCString& str);
      UtlString (RWCSubString& ss);
      UtlString (float f);
      UtlString (UtlID id);
      UtlString (int i);
      UtlString (RWSize_T ic);
      UtlString (double d);
      UtlString (const UtlString& that)
      {
        this->operator =(that.data());
      }
      virtual ~UtlString();
      operator float () const;
      operator UtlID () const;
      operator int () const;
      float AsFloat () const;
      int AsInt () const;
      double AsDouble () const;
      troint64 AsLong () const;
      trouint64 AsULong () const;
      UtlString& operator << (const int value);
      UtlString& operator << (const troint64 value);
      UtlString& operator << (const float value);
      UtlString& operator << (const double value);
      UtlString& operator << (const char value);
      UtlString& operator << (const RWCString& value);
      UtlString& operator << (const short value);
      UtlString& operator << (const bool value);
      UtlString& operator << (const unsigned char value);
      UtlString& operator << (const unsigned short value);
      UtlString& operator << (const trouint64 value);
      UtlString& operator << (const char *value);
      UtlString& operator =  (const char *value)
      {
        this->remove(0,this->length());
        return *this;
      }
};

我在下面的代码中收到错误。

UtlString errMsg;

  errMsg = UtlString("DB Error: ")
    + UtlString(aStatus.message())
    + " ("
    + UtlString(aStatus.errorCode())
    + ") - "
    + UtlString((double)aStatus.vendorError1())
    + ": "
    + UtlString((double)aStatus.vendorError2())
    + ", "
    + UtlString(aStatus.vendorMessage1())
    + ": "
    + UtlString(aStatus.vendorMessage2());

错误:重载“UtlString :: operator =(const char *)”和“UtlString :: operator =(const UtlString&amp;)”之间的歧义。

请你帮我解决这个错误。我不明白UtlString::operator=(const UtlString&)即将到来的地方。我从未宣布过这样的经营者。

使用CC:Sun C ++ 5.8编译器。

1 个答案:

答案 0 :(得分:-2)

errMsg = UtlString...是一个初始化,因此编译器可以自由地考虑复制构造函数。这就是您从中获得有效赋值运算符UtlString::operator=(const UtlString&)的地方。