2

I saw this in some code I try to recompile for VC++ 2013:

std::string str;
[...]
str = {}

VC++ 2013 complains about that:

error C2593: 'operator =' is ambiguous

So I am trying to understanding what it specifically does.

So why use str = {} instead of str = ""? What are the differences if any?

4

2 回答 2

3

我相信这是 MSVC 中的一个错误。这意味着什么:它将空分配initializer_list<char>给您的str变量。您可以通过使用显式创建来解决此问题:str = std::string{};它将保留原始含义并与 MSVC 一起使用。我建议向 MS Connect 提交错误报告。

于 2013-11-09T09:42:46.250 回答
1
str = {""}

效果很好并保留了括号分配的原始含义。

于 2013-11-10T07:48:31.877 回答