Possible Duplicate:
What are access specifiers? Should I inherit with private, protected or public?
How can I create a derived class in C++ which preserves the properties and methods' access specifier like this:
class Base
{
private:
void base_private();
protected:
void base_protected();
public:
void base_public();
};
class A: [what type is appropriate here?] Base
{
public:
void test() {
base_protected(); // Ok
}
};
class B: [what type is appropriate here?] A
{
public:
void test() {
base_protected(); // Ok
}
};
int main()
{
A a;
B b;
a.base_public(); // Ok
a.base_protected(); // Not Ok
b.base_protected(); // Not Ok
b.test(); // Ok
return 0;
}
I mean base_protected()
method is still protected in derived classes but base_public()
is public.