What you describe is routinely schema of using inheritance: A <- B <- C. It does not even require C++ multiple inheritance:
class A {
public:
void Fun() {}
};
class B : public A {
};
class C : public B {
};
You cannot limit access to the instance function
A.Fun
though. It would be possible if this function was virtual and overridden in
B
. In this case, you can limit access and cannot make access more open.
You can formally declare private Fun, but it would not work as expected as it would be the
different
Fun
with the same name hiding the inherited
Fun
. It could be called anyway, consider this:
class A {
public:
void Fun() {}
};
class B : public A {
private:
void Fun() {} };
void TestHiding() {
B b;
A *b_as_a = &b;
b_as_a->Fun(); }
If this question was difficult to you, you're not yet ready to do any C++ development using OOP. Step back and learn you C++ course and related topics.
—SA