0
class Base{
    public:
    virtual void func()
    {
        cout<< "base";
    }
};

class Derived : public Base{
    private:
    void func(){
        cout<< "derived";
    }
};

int main() {
    Base *b = new Derived();
    b->func(); //output  = "derived"
    return 0;
}

When overloading the base function on creation of derived class virtual function , shouldn't vtable also take in the access specifier of the derived class?(for me it seems to be against c++ principles) . Please also explain the decision why the base class access specifier is followed.

Azazel
  • 11
  • 2
  • Access specifiers in C++ aren't what most people think they are. So it's not "against C++ principles". It may be against principles of other languages (drawing a blank here, however), but C++ is not those languages. – StoryTeller - Unslander Monica Apr 09 '18 at 10:05
  • 1
    Could you please clarify how "Access specifiers in C++ aren't what most people think they are. " ? – Azazel Apr 09 '18 at 10:08
  • They don't affect name visibility. They only affect in which scopes a name can be used. It's not uncommon for the unaware to be stumped when, say, overload resolution picks a private overload. They expect the name to not be there. But it is. – StoryTeller - Unslander Monica Apr 09 '18 at 10:23

0 Answers0