Few simple questions regarding inheritance

Hello,
let's assume we have the following class :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class A {
  int a;

protected:
  int b;

public:
  int c;

  void testFunction();
}

class B : public A {

}


Class B will have also int a; int b; int c;, but they will be not the same as for class A. They'll be different variables for class A and class B.
But if I want to access the protected members of class A from class B, how can I do it ? And if I want to call the function of class A from class B, how to do it ?
Can I just write A::testFunction() inside B ? Or I'm allowed to do that only if it's virtual function.
And can I write A::c from inside B, to access that variable of class A ?

Thank you in advance. It seems I'll need to clean some concepts regarding inheritance...
You can access members from class B the same way you access them in class A.
If you have members in class B with the same name of members inherited from class A, then you have to specify A::Amember to access the parent's members.
Notice that B can't access A::a as it is private
Aha, I see. So when B is derived from A, it takes it members. And now
A have member int a; and B have member int a;
And A can be accessed through A::a;

Thank you, Bazzy. :)
Except that in your example A::a is private so derived classes can't access it
Yes, of course. :)
Topic archived. No new replies allowed.