Explain the difference between public, protected, and private inheritance.
Last updated
The specifier caps base member visibility in the derived class:
publicpreserves access,protectedmakes public/protected members protected, andprivatemakes them private. Base private members are always inaccessible.Only public inheritance ("is-a") allows implicit Derived*-to-Base* conversion and thus polymorphism. Protected/private model "implemented-in-terms-of" reuse.
The default is
privateforclassandpublicforstruct.