class MyClass
{
public:
~MyClass() {}
MyClass():x(0), y(0){} //default constructor
MyClass(int X, int Y):x(X), y(Y){} //user-defined constructor
MyClass(cons
The copy constructor may be elided in such a case.
Likewise with MyClass MyObj = MyClass( 1, 2 );
.
And with
std::string str = "hello";
Such code has an implicit constructor call to convert the char*
to a std::string
.
std::string str = std::string( "hello" ); // same, written more verbosely
Without copy elision, the "easy" string initialization by assignment syntax would incur an additional deep copy. And that syntax is 99% equivalent to what you have.