Given that we have overloaded methods in base class, and a derived class that was inherited as private/protected.
- Can we restore only one/several of the original access level of the overloaded methods?
- On GCC 4.4.0 i try to put the base methods under protected access, then inherited it using private access. When i try to restore the access level to public, it works! Is this how its suppose to work? or is it a bug on the compiler? To my understanding, restoring access level shouldn’t be able to be used to promote or demote a member’s access level.
Code snippet :
class base {
public:
void method() {}
void method(int x) {}
protected:
void method2() {}
};
class derived : private base {
public:
base::method; // Here, i want to restore only the none parameterized method
base::method2; // method2 is now public??
};
Changing accessibility of inherited functions through a
usingdeclaration cannot be done selectively on given overload for the simple reason that ausingdeclaration only introduces a name into the declarative region and that by definition, functions overloads share the same name.The only alternative I see here is to use trivial forwarding functions :
I’m not quite sure I understand your second question, but yes : you can change base members accessibility in a derived class through
usingdeclarations.