视觉c++运算符 += 不明确

发布于 2024-11-18 07:33:53 字数 315 浏览 0 评论 0原文

CString szMsg;

//Other non related code

//stOrderInfo.bstrOrderNum is defined as a _bstr_t
szMsg += ", Order: " + stOrderInfo.bstrOrderNum;

我将上述内容从 VS 6.0 转换为 VS2k10,并且收到以下错误(在 VS 6.0 中编译):

error C2593: 'operator +=' is ambiguous

这到底是什么意思以及如何修复它?

CString szMsg;

//Other non related code

//stOrderInfo.bstrOrderNum is defined as a _bstr_t
szMsg += ", Order: " + stOrderInfo.bstrOrderNum;

I'm converting the above from VS 6.0 to VS2k10 and I'm getting the following error (compiles in VS 6.0):

error C2593: 'operator +=' is ambiguous

What exactly does this mean and how can I fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

世界和平 2024-11-25 07:33:53

因为您已经硬编码了 ", Order: " 编译器很难决定它应该是什么类型。

明显的类型应该是CString,但它可能会尝试将其转换为其他字符串类型,并向其中添加数字。

因此它可能无法确定它是 CString 还是其他字符串类型。因此它无法决定您要添加到 szMsg 中的类型。

您可以只使用类型转换:

szMsg += (CString)(", Order: ") + (CString)((char *)(stOrderInfo.bstrOrderNum));

在字符串类型之间转换:

如何:在各种字符串类型之间进行转换

Because you've hard-coded ", Order: " the compiler is having a hard time to decide which type it should be.

The obvious type should be CString, but it might try to make it to some other string type, and add the number to it.

So it probably can't decide if it's a CString or another string type. So it can't decide what type you're adding to szMsg.

You could just use a type cast:

szMsg += (CString)(", Order: ") + (CString)((char *)(stOrderInfo.bstrOrderNum));

Cast between string types:

How to: Convert Between Various String Types

心的位置 2024-11-25 07:33:53

这意味着编译器无法选择对 BSTR + 字符连接使用哪个 + 运算。存在三种类型不匹配:CString、_bstr_t 和 char。
尝试将所有三个操作数统一为单一类型,例如 CString

This means that compiler cannot choose which + operation to use for BSTR + char concatenations. You have a mismatch of three types: CString, _bstr_t, and char.
Try to unify all three operands to a single type, e.g. to CString

温柔女人霸气范 2024-11-25 07:33:53

已知 CString::operator+= 的实现在 Visual Studio 2010 中发生了变化。例如,在以前的版本中,它可以正常处理嵌入的空字符,就像 operator+ 一直在做的那样,但新版本没有。所以可能和这个有关。

编辑
有关此主题的讨论的链接:
http://social.msdn.microsoft.com/Forums/en-US/vcmfcatl/thread/c5d7f383-da80-4776-b9b8-a6065839bd87

The implementation of CString::operator+= is known to have changed in Visual Studio 2010. For example in previous versions it handled embedded null characters OK, just like operator+ keeps doing, but the new version doesn't. So it might be related to this.

EDIT
Link to discussion on this topic:
http://social.msdn.microsoft.com/Forums/en-US/vcmfcatl/thread/c5d7f383-da80-4776-b9b8-a6065839bd87

时光倒影 2024-11-25 07:33:53

最好使用CString::AppendFormat。但请确保您传递正确的格式说明符。

Better use CString::AppendFormat. But ensure you pass correct format-specifier.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文