I'm new to C++ classes, and I have some questions about nested classes.
What I Know
- classes in C++ are set of variables and functions set by 'private' by default.
- when you create a class, an object is created.
- I understand the basic concepts of constructors.
I know that I can make 'classes' as an variable in an another 'class', also known as nested class, but I really can't figure out how it is done exactly. If I create an nested class, does it create object itself, and objects from the class variables inside the nested class?
I'm having problems initializing class variables in nested class using constructors.
For example
class Point {
int xpos;
int ypos;
}
Let's say that I created a class containing 2 int variables.
class Rectangle {
Point upLeft;
Point lowRight;
}
Then, I created a Rectangle class having 2 'Point class' as variables.
Rectangle rec1;
Then, I created an object rec1.
How can I initialize the 2 xpos and 2ypos using constructors in Rectangle Class?