I have this class:
class A {
private:
int player;
public:
A(int initPlayer = 0);
A(const A&);
A& operator=(const A&);
~A();
void foo() const;
};
and I have function which contains this row:
A *pa1 = new A(a2);
can somebody please explain what exactly is going on, when I call A(a2) compiler calls copy constructor or constructor, thanks in advance
Assuming
a2is an instance ofA, this calls the copy constructor.It will call
operator newto get dynamic memory for the object, then it will copy-construct a new object into the memory, then return a pointer to that memory.