Using the Scope Operator to Use Hidden Members

We can use a hidden base-class member by using the scope operator:

struct Derived : Base {
    int get_base_mem() { return Base::mem; }
    // ...
};

The scope operator overrides the normal lookup and directs the compiler to look for mem starting in the scope of class Base. If we ran the code above with this version of Derived, the result of d.get_mem() would be 0.


Image Best Practices

Aside from overriding inherited virtual functions, a derived class usually should not reuse names defined in its base class.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.46.92