Class Inheritance

From what I have and read, a derived class can access all of the non-private members of its base class. My newest assignment works with class derivatives and operator overloading. the assignment states that the derived class inherits all members of the base function. Is this even possible? I would like to know before I question the teacher.....
It can see the assignment operator of the base class, the derived class has its own which is different.
but if some members are private, such as variables, how does the derived class access them?
ok, after reading a little further, I am allowed to add functions to the base class to allow the derived class to access private data......
Does it even make sense to combine operator overloading with polymorphism? In a majority of cases, it does not, so I generally say you should pick one or the other. Trying to mix operator overloading with polymorphism is usually a nightmare and a half because C++ isn't designed to support it.
I'm still confused. I like the idea of polymorphism but lets say, I have a bankaccount class and checkingaccount class that is derived from bankaccount. All of the info, such as accountname, balance, accountnumber, etc...is private. How does the private data, such as balance get assigned to the checkingaccount class?
What is functionally different between a 'bank account' and a 'checking account'? What does 'checking account' add that should not be in 'bank account'? In my opinion, there is no distinction to be made and so you should not need to separate the concepts into two different classes.
Last edited on
How does the private data, such as balance get assigned to the checkingaccount class?
It doesn't.

Think of a class as a structure that occupies memory. It always has a size. A derived class will add to that size.

For example:
1
2
3
4
5
6
7
class B {
    char code[4];
};

class D : public B {
    double price;
};

If the size of a double is 8 bytes, the size of B is 4 bytes and the size of D is 12 bytes.

As B::code is private, it is not visible to D. But D carries around B::code wherever it's instantiated. It just doesn't have access to it.
As B::code is private, it is not visible to D. But D carries around B::code wherever it's instantiated. It just doesn't have access to it.

ok, that makes sense. I guess I am making it harder than it needs to be.
Topic archived. No new replies allowed.