Yogi Watcher

Hello,

I am sure I am missing something or may be I don't understand it properly but can somebody explain me why first line results into compilation error but second does not:

Code Snippet
std::string tmp_Error = 5 ; // Results in C2440 error
std::string tmp_noError ;
tmp_noError = 5 ; // No compilation error

Thanks and Regards

Yogi Watcher




Re: Visual C++ Language Why no compilation error - Assigning int to std::string?

Nishant Sivakumar

There is an = operator overload that takes the string's element type as argument. In this case it would most likely be char - so it works fine.

But there's no equivalent copy constructor. You could do something like this though :-

std :: string tmp_Error1 (1, 65)

This will make tmp_Error1 equal to "A".