The C++ string type has an implicit conversion constructor that accepts as input a const char *
. Consequently, it is legal to initialize a C++ string using a C-style string, because C++ will interpret this as a call to the implicit conversion constructor.
In this case, the code
string str = "123";
is equivalent to
string str("123");
which more explicitly looks like a constructor call.
Note that it is extremely rare to see something like
classType p = classType();
The more proper way to say this would be to just write
classType p;
which implicitly calls the default, no-argument constructor.
Hope this helps!