I have made a simple application with move copy constructor and move copy assignment operator and on each of them I have made a cout statement just to tell me, which are being executed. But during execution, I did not see any statement from the move copy operators but only from default one which the compiler already provides. Here is my code:
#include <iostream>
#include <string>
using namespace std;
class Names{
private:
string* name;
public:
Names(string place_name){
cout << "Overloaded constructor" << endl;
name = new string;
*name = place_name;
}
//copy constructor
Names(Names& cpy){
cout << "Copy constructor" << endl;
name = new string;
*name = *cpy.name;
}
//assignment
Names& operator =(const Names& cpy){
cout << "Assignment operator" << endl;
name = new string;
*name = *cpy.name;
return *this;
}
//move constructor
Names(Names&& cpym){
cout << "Copy move constructor" << endl;
name = cpym.name;
cpym.name = NULL;
}
//move assignment operator
Names& operator=(Names&& cpym){
cout << "Copy assignment operator" << endl;
delete name;
name = cpym.name;
cpym.name = NULL;
return *this;
}
//destructor
~Names(){
cout << "Deallocating memory" << endl;
delete [] name;
}
};
int main(){
Names nme("Bob");
Names copin("something");
copin = nme;
system("pause");
return 0;
}
and here is the output
so the main question are
1) Why isn't the cout statement being show for the move constructor?
2) Is my declaration for move constructor correct
and Thanks you.