This question might be silly, but I want to know, if a copy constructor is invoked when a pointer to an object is returned by a function?
Also,consider following:
A* a1 = new A();
A* a = a1.GetPointer();
A* GetPoineter()
{
.....
return new A();
}
so does
A* a = a1.GetPointer();
call copy constructor?
also if I delete a, will it delete the address pointed by a1 also?
No, it does not call the copy constructor since you are returning the address of the object, not the object itself.
delete a;will only delete the object allocated in theGetPoineterfunction.a1is untouched since it points to a completely different object.