OK, I think I see where you may be confused.
String mystr1 = "a";
In this case the compiler can optimise the statement to an existing constructor (
String(char* str)
), because the creation and assignment happen together.
String mystr2;
mystr2 = "aa";
In this case the creation of the
String
object does not have any initialiser so the default constructor is called. On the next line a value ("aa") is to be assigned to
mystr2
, and the way to do that is to construct a temporary
String
object (using an appropriate constructor), and then use the assignment operator to set the value of the previously created one (
mystr2
). It could be argued that the compiler should optimise this to the same as case 1, as the two operations are in sequence.
String mystr3("aaa");
In this case the code is a constructor call so the constructor that takes a
char*
will be called.
String mystr3(mystr2);
In this case the parameter is a
String
object so the compiler will generate a call to the copy constructor.