C++ inherited class has member of same name

2019-06-15 01:36发布

In C++ you can put a member in a base class and a member with the same name in the inherited class.

How can I access a specific one in the inherited class?

标签: c++ class base
7条回答
Viruses.
2楼-- · 2019-06-15 02:23
#include <iostream>
using namespace std;

struct Base {
    int memfcn();
};

struct Derived : Base {
    int memfcn(int);
};

int main() {
    Derived d;
    Base b;
    d.Base::memfcn();  //you can even use :: in conjunction with dot(.). This is new to me.
}
查看更多
登录 后发表回答