免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5111 | 回复: 4
打印 上一主题 下一主题

[C++] c++重载错误:有相似的转换 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-07-17 15:29 |只看该作者 |倒序浏览
本帖最后由 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

论坛徽章:
14
巨蟹座
日期:2013-11-19 14:09:4615-16赛季CBA联赛之青岛
日期:2016-07-05 12:36:0515-16赛季CBA联赛之广东
日期:2016-06-29 11:45:542015亚冠之全北现代
日期:2015-07-22 08:09:472015年辞旧岁徽章
日期:2015-03-03 16:54:15巨蟹座
日期:2014-12-29 08:22:29射手座
日期:2014-12-05 08:20:39狮子座
日期:2014-11-05 12:33:52寅虎
日期:2014-08-13 09:01:31巳蛇
日期:2014-06-16 16:29:52技术图书徽章
日期:2014-04-15 08:44:01天蝎座
日期:2014-03-11 13:06:45
2 [报告]
发表于 2010-07-17 16:31 |只看该作者
没有直接的 OdString + wchar_t ,于是编译器发现wchar_t可以转化为OdChar,以适应OdString+OdChar这个重载;
也可以将OdString转化为OdChar,以适应OdChar+wchar_t这个重载;
……

论坛徽章:
0
3 [报告]
发表于 2010-07-17 16:36 |只看该作者
谢谢楼上,我也是刚刚发现,然后强制转化为了OdChar,能看看我的另一帖么?

论坛徽章:
0
4 [报告]
发表于 2010-07-17 16:40 |只看该作者
回复 2# bruceteen


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

论坛徽章:
0
5 [报告]
发表于 2010-07-17 16:41 |只看该作者
感觉应该转化为const OdChar *
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP