[Solved] Upcast, downcasting, and hiding methods in C++ [closed]


About question #1: yes, if you provide a factory method along with your ‘simple’ interface:

class B {
public:
    static B * create();
    virtual void simple() = 0;
};

in B’s implementation file (cpp):

B *B::create()
{
    return new D(); //or whatever 'hidden' implementation 
}

About your #2: hiding functionality means simplification in the first place, and is intended as a favour toward the library users, not a punishing constraint. So, hide the D class entirely and let the (good) users be happy with it.

2

solved Upcast, downcasting, and hiding methods in C++ [closed]