VS2008 C ++ compiler error?
3 answers
The second example is really initialization, not assignment, i. That is, it calls the constructor, not operator=
. Obviously the class string
doesn't have a constructor that takes an integer as an argument, but the assignment operator is fine. And the reason you get an emoji is because it is a character with an ASCII value of 1.
By the way, this is not the case for Visual Studio. Any C ++ compiler should behave the same.
+4
source to share
Not relevant to the question, but why don't you (and many others) post the compiled code. Will be:
#include <string>
using namespace std;
int main() {
string name;
name = 1;
string name2 = 1;
}
was it too much to ask for? With this in mind, we can see that "string" actually refers to std :: string, and not some random class.
+1
anon
source
to share