You need to use std::move for the move constructor and move assignment operator to work. See my main function below:
Names A(Names name) {
return name;
}
int main(){
Names nme("Bob");
Names copin("something");
cout << "before std::move(nme);" << endl;
copin = std::move(nme);
cout << "before std::move(GetName());" << endl;
Names tom = std::move(nme);
cout << "before A(Names(\"dick\");" << endl;
// move constructor is also called when using temp rvalue
Names dick = A(Names("dick"));
system("pause");
return 0;
}
Output:
Overloaded constructor
Overloaded constructor
before std::move(nme);
Copy assignment operator
before std::move(GetName());
Copy move constructor
before A(Names("dick");
Overloaded constructor
Copy move constructor
Copy constructor
Deallocating memory
Deallocating memory
Press any key to continue . . .
One more issue, your destructor should not delete [] name, just delete name;