Click here to Skip to main content
15,887,683 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: A programming question Pin
David O'Neil23-Sep-20 21:27
professionalDavid O'Neil23-Sep-20 21:27 
GeneralRe: A programming question Pin
David O'Neil23-Sep-20 21:56
professionalDavid O'Neil23-Sep-20 21:56 
GeneralRe: A programming question Pin
Randor 23-Sep-20 22:10
professional Randor 23-Sep-20 22:10 
RantRe: A programming question Pin
W Balboos, GHB24-Sep-20 2:40
W Balboos, GHB24-Sep-20 2:40 
GeneralRe: A programming question Pin
Randor 24-Sep-20 3:36
professional Randor 24-Sep-20 3:36 
GeneralRe: A programming question Pin
W Balboos, GHB24-Sep-20 5:45
W Balboos, GHB24-Sep-20 5:45 
GeneralRe: A programming question Pin
David O'Neil24-Sep-20 8:52
professionalDavid O'Neil24-Sep-20 8:52 
GeneralRe: A programming question Pin
Stefan_Lang23-Sep-20 23:01
Stefan_Lang23-Sep-20 23:01 
A good example, but most cases I've come across caring about these kind of problems use delegates instead of inheritance. Delegates come with the additional advantage to keep what would otherwise be the base class entirely out of the API (i. e. the headers).

I. e. instead of putting this into your header:
C++
class MyEncapsulatedBaseClass { // ...
public:
   void doAwesomeStuff();
};
class MYAPI MyDerivedClass : private MyEncapsulatedBaseClass { // ... 
public:
   void doMoreAwsomeStuff(); // calls doAwesomeStuff() and more
};

you only put this in your header:
C++
class MYAPI MyClass {
   class MyEncapsulatedClass* delegate;
public:
   void doMoreAwesomeStuff(); // uses delegate to do awesome stuff and then does more
};

The advantage of the latter is that you can switch to a different encapsulated class or change the function and data members in that class without affecting the API delivered to your clients.

The only advantage of the former I can think of is, that with protected inheritance, that protection is not final, at least not for virtual member functions: another derived class can overide any protected virutal base function with a public one, making it accessible again! (Of course, if you want to retain that option, the question is why don't you use public inheritance to start with ? WTF | :WTF: )
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

PraiseRe: A programming question Pin
Randor 24-Sep-20 0:41
professional Randor 24-Sep-20 0:41 
GeneralRe: A programming question Pin
Kornfeld Eliyahu Peter23-Sep-20 21:06
professionalKornfeld Eliyahu Peter23-Sep-20 21:06 
GeneralRe: A programming question Pin
Daniel Pfeffer23-Sep-20 21:07
professionalDaniel Pfeffer23-Sep-20 21:07 
GeneralRe: A programming question Pin
Rage23-Sep-20 21:20
professionalRage23-Sep-20 21:20 
GeneralRe: A programming question Pin
David O'Neil23-Sep-20 21:25
professionalDavid O'Neil23-Sep-20 21:25 
GeneralRe: A programming question Pin
Rage23-Sep-20 21:30
professionalRage23-Sep-20 21:30 
GeneralRe: A programming question Pin
David O'Neil23-Sep-20 21:34
professionalDavid O'Neil23-Sep-20 21:34 
GeneralRe: A programming question Pin
Rage23-Sep-20 21:37
professionalRage23-Sep-20 21:37 
GeneralRe: A programming question Pin
David O'Neil23-Sep-20 21:39
professionalDavid O'Neil23-Sep-20 21:39 
GeneralRe: A programming question Pin
Shao Voon Wong23-Sep-20 21:55
mvaShao Voon Wong23-Sep-20 21:55 
GeneralRe: A programming question Pin
David O'Neil23-Sep-20 22:01
professionalDavid O'Neil23-Sep-20 22:01 
GeneralRe: A programming question Pin
Arthur V. Ratz23-Sep-20 22:09
professionalArthur V. Ratz23-Sep-20 22:09 
GeneralRe: A programming question Pin
Nemanja Trifunovic24-Sep-20 3:13
Nemanja Trifunovic24-Sep-20 3:13 
GeneralRe: A programming question Pin
RustyF24-Sep-20 20:56
RustyF24-Sep-20 20:56 
GeneralRe: A programming question Pin
giulicard24-Sep-20 22:01
giulicard24-Sep-20 22:01 
GeneralRe: A programming question Pin
Stuart Dootson24-Sep-20 23:13
professionalStuart Dootson24-Sep-20 23:13 
GeneralRe: A programming question Pin
patbob28-Sep-20 14:17
patbob28-Sep-20 14:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.