1

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

下面是这个类的声明。

#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&)”之间的歧义。

你能帮我解决这个错误吗?我不明白UtlString::operator=(const UtlString&)要来的地方。我从未宣布过这样的运营商。

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

4

1 回答 1

-2

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

于 2012-04-24T12:58:24.673 回答