0
(a) When p3 object is created, specify which constructor gets invoked and why? (b) Write complete definition for Constructor3.
class player { int health; int age; public: player(){health=7;age=17;} //Constructor1 player(int h,int a){health=h;age=a;} //Constructor2 player(player &p){} //Constructor3 ~player(){cout<<"<Memory Free";} //Destructor }; int main() { player p1(9,26); //Statement1 player p3=p1; //Statement3 return0; }
1 Respuesta
+ 2
Seems like a Turbo C++ School assignment to me.
When object "p3" is created, Constructor 3 gets called (a copy constructor).
//Definition for Constructor 3
player(player &p)
{
health = p.health;
age = p.age;
}
From next time onwards, show us your efforts at solving such problems before posting again...