Implementing protected / private inheritance in the compiler

advertisements

If a class derives from another class like

class B{};
class D : private B{};

then I can not create derived class objects like:-

B* ptr = new D;

If I check the assembly difference of this code vs assembly code of class D deriving from class B publically, I don't find any differnce.

Can anyone explain exactly how and at what stage the complier is differentiating between public / protected and private inheritance.


The compiler checks protection (public/private) in the frontend while parsing your code. Once it gets to the optimizer and code generation they are gone.