"The compiler implicitly creates a default constructor in a class that does not define a constructor. Such a constructor does not initialize the class’s data members,but does call the default constructor for each data member that’s an object of another class. An uninitialized variable typically contains a “garbage” value."
so what is this thing talking about
Such a constructor does not initialize the class’s data members,but does call the default constructor for each data member that’s an object of another class.
i understood that constructors are functions with same name as the class, but right here it talks about data member having default constructor and i understood data members to be Variables so thats why i am lost
Lets say I have two classes, classOne and classTwo.
Both of them have constructors. Whenever an instance of classOne is created, its constructor is called. Whenever an instance of classTwo is created, its constructor is called.
Here's classOne:
1 2 3 4 5
class classOne
{
classTwo x;
classTwo y;
};
When I create an instance of classOne, the constructor of classOne is called. This constructor then has to create the member variable x and the member variable y. What does it do? When creating the variable x, it calls the classTwo constructor. When creating the variable y, it calls the classTwo constructor.