Hi there,
Let's look at your code:
1 2 3 4 5
|
void main() {
Residential_Building r;
Building* b = &r;
}
|
You create an object r of type Residential building. This object has all the possibilities your residential_building class defines. Because it's a "regular" type, as opposed to a pointer, they are accessible using the "member of" or "dot" operator, for example:
r.getMaterial();
.
For the sake of this explanation, let's say that an object of Building takes 4 bytes of memory, but the residential_building adds funcionality, so it requires 6 bytes of memory.
When you do
Building* b = &r;
you are telling the compiler: "I create a pointer to a building object, which is 4 bytes of size, and I set the pointer to point to the address of the residential_building instance i just created." Because you have told the compiler that "b" is pointing to a "Building", only 4 bytes in size, it will only be able to access the functionality present in those 4 bytes.
It's a bit simplified, but I hope that makes sense to you.
Let us know if you have any further questions.
All the best,
NwN