Having following code:
#include <iostream>
#include <vector>
using namespace std;
class CIntPtr {
public:
int* ptr;
public:
CIntPtr() {
// Default constructor
cout << "Calling Default constructor\n";
ptr = new int;
}
CIntPtr(const CIntPtr& obj) {
// Copy Constructor
// copy of object is created
this->ptr = new int;
// Deep copying
cout << "Calling Copy constructor\n";
}
CIntPtr(CIntPtr&& obj) {
// Move constructor
// It will simply shift the resources,
// without creating a copy.
cout << "Calling Move constructor\n";
this->ptr = obj.ptr;
obj.ptr = NULL;
}
~CIntPtr() {
// Destructor
cout << "Calling Destructor\n";
delete ptr;
}
};
int main() {
CIntPtr bar = CIntPtr(); // move-construction
return 0;
}
There is only "normal" ctor called. Should't it be ALSO move ctor get called since there is a temp obj created in line: CIntPtr bar = CIntPtr()
?
PS. Can someone provide/lists all the possible cases when move constructor is called?