Why do we actually need Private or Protected inheritance in C++?

后端 未结 7 1022
情话喂你
情话喂你 2020-11-28 01:44

In C++, I can\'t think of a case in which I would like to inherit private/protected from a base class:

class Base;
class Derived1 : private Base;
class Deri         


        
7条回答
  •  情话喂你
    2020-11-28 02:29

    I once implemented these data structures as classes:

    • Linked list
    • Generic array (abstract)
    • Simple array (inherits from generic array)
    • Big array (inherits from generic array)

    The big array's interface would make it look like an array, however, it was actually a linked list of fixed-size simple arrays. So I declared it like this:

    template 
    class CBigArray : public IArray, private CLnkList {
        // ...
    

提交回复
热议问题