I want to know if a class contains an object of another class and both classes have constructors, how does initializing in the constructor in the class that contains the object of another class work. and what is the order of initialization?
class Person
{
string name;
int age;
public:
Person()
{
name="NULL";
age=0;
}
};
class Student
{
int roll_no;
Person p;
int division;
public:
Student()
{
roll_no=0;
division=0;
}
};
In this example, in the student class constructor, do we need to put code like
Student()
{
roll_no=0;
p.Person();
division=0;
}
Do we need to put p.Person();
to initialize p?
Doesn't p automatically get initialized when it is created because it has a constructor. what is the order of initializing through constructors in cases like this?