Private and Protected Inheritance
Hi!
I do not know if it is a standard, but I got surprised when I made a
private inheritance and called, inside the derived class, a public/
protected member function from the base class without any compiler
complain (I got a similar feedback when using protected inheritance).
Is that a standard?
I thought that when it comes to private inheritance, the derived class
could not access any member from the base class, since all of them
would become private too.
If what I am saying is not clear enough, see the code below:
#include<iostream>
using namespace std;
class c1 {
public:
c1() : i(10) {cout << "c1::c1()" << endl;}
~c1() {cout << "c1::~c1()" << endl;}
void f() {cout << "c1::void f()" << endl;}
void g() {cout << "c1::int g()" << endl;}
protected:
int h() {
cout << "c1::int h()" << endl;
cout << "i = " << i << endl;
return(0);
}
private:
int i;
};
class c2 : private c1 {
public:
c2() : i(5) {cout << "c2::c2()" << endl;}
~c2() {cout << "c2::~c2()" << endl;}
void f1() {
cout << "c2::void f1()" << endl;
f(); // HERE
g(); // HERE
h(); // HERE
}
private:
int i;
};
int main()
{
c2 obj2;
obj2.f();
return(0);
}
I appreciate any comment, suggestion, etc.
Thank you!
Marcelo de Brito