+ -
当前位置:首页 → 问答吧 → c++重载错误:有相似的转换

c++重载错误:有相似的转换

时间:2010-07-17

来源:互联网

本帖最后由 lishizelibin 于 2010-07-17 15:32 编辑

头文件中
  friend FIRSTDLL_EXPORT OdString operator+(const OdString& string1, const OdString& string2);
  friend FIRSTDLL_EXPORT OdString operator+(const OdString& string, OdChar ch);
  friend FIRSTDLL_EXPORT OdString operator+(OdChar ch, const OdString& string);

  friend FIRSTDLL_EXPORT OdString operator+(const OdString& string1, const OdChar* string2);
  friend FIRSTDLL_EXPORT OdString operator+(const OdChar* string1, const OdString& string2);

实现文件中
OdString strSheetName = strSeed + DD_T('-') + strLayoutName;   //该句出现错误

strSeed 和 strLayoutName 都是OdString类型
#define DD_T(x) __DD_T(x)
#define __DD_T(x) L ## x

error C2666: “operator +”: 4 个重载有相似的转换
4>        可能是“OdString operator +(const OdString &,OdChar)”[通过使用参数相关的查找找到]
4>        或“内置 C++ operator+(OdChar, wchar_t)”
4>        或“内置 C++ operator+(const wchar_t *, wchar_t)”
4>        或“内置 C++ operator+(const char *, wchar_t)”
4>        试图匹配参数列表“(OdString, wchar_t)”时

运行环境:VS2005

作者: lishizelibin   发布时间: 2010-07-17

没有直接的 OdString + wchar_t ,于是编译器发现wchar_t可以转化为OdChar,以适应OdString+OdChar这个重载;
也可以将OdString转化为OdChar,以适应OdChar+wchar_t这个重载;
……

作者: bruceteen   发布时间: 2010-07-17

谢谢楼上,我也是刚刚发现,然后强制转化为了OdChar,能看看我的另一帖么?

作者: lishizelibin   发布时间: 2010-07-17

回复 bruceteen


我的另一帖   
http://bbs.chinaunix.net/thread-1750904-1-1.html

作者: lishizelibin   发布时间: 2010-07-17

感觉应该转化为const OdChar *

作者: lishizelibin   发布时间: 2010-07-17