Korchkidu
Korchkidu

Reputation: 4946

Why std::string str = {}?

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?

Upvotes: 2

Views: 599

Answers (2)

pr.
pr.

Reputation: 43

str = {""}

Works well and preserves original meaning of bracket assignment.

Upvotes: 1

ixSci
ixSci

Reputation: 13698

I believe it is a bug in MSVC. What it means: it assigns empty initializer_list<char> to your str variable. You can fix this by using explicit creation:str = std::string{}; it will preserve original meaning and will work with MSVC. I'd recommend to file a bug report to MS connect.

Upvotes: 3

Related Questions