C
Christian Meier
Hi dear programmers
I looked for the difference between private and protected inheritance, but
couldn't find anything.
Here is my sample code:
#include <iostream>
using std::cout;
using std::endl;
class Base
{
public:
Base() { cout << "***Base constructor called***" << endl; }
~Base() { cout << "***Base destructor called***" << endl; }
protected:
void coutAnything() { cout << "Anything" << endl; }
};
class Derived : protected Base
{
public:
Derived() { cout << "***Derived constructor called***" << endl; }
~Derived() { cout << "***Derived destructor called***" << endl; }
void coutAnythingDerived() { coutAnything(); }
};
int main()
{
Derived derivedInstance;
derivedInstance.coutAnythingDerived();
}
It does not matter if I have a private or a protected inheritance.... Can
anyone add a function where I can see the difference? The difference to a
public inheritance is clear by the way. I have only problems with protected
/ private.
Thanks for your help!
Regards,
Chris
I looked for the difference between private and protected inheritance, but
couldn't find anything.
Here is my sample code:
#include <iostream>
using std::cout;
using std::endl;
class Base
{
public:
Base() { cout << "***Base constructor called***" << endl; }
~Base() { cout << "***Base destructor called***" << endl; }
protected:
void coutAnything() { cout << "Anything" << endl; }
};
class Derived : protected Base
{
public:
Derived() { cout << "***Derived constructor called***" << endl; }
~Derived() { cout << "***Derived destructor called***" << endl; }
void coutAnythingDerived() { coutAnything(); }
};
int main()
{
Derived derivedInstance;
derivedInstance.coutAnythingDerived();
}
It does not matter if I have a private or a protected inheritance.... Can
anyone add a function where I can see the difference? The difference to a
public inheritance is clear by the way. I have only problems with protected
/ private.
Thanks for your help!
Regards,
Chris