Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I only have one question: why you private inheritance at all ?</p> <p>Inheritance is quite a broken concept, in my opinion, because it violates the One Responsibility principle:</p> <ul> <li>you inherit the interface</li> <li>you inherit the implementation</li> </ul> <p>Unfortunately inheritance is required for polymorphism in Object-Oriented code, so you can't shy away from it in this case.</p> <p>But here you explicitly wish NOT to use polymorphism, so I find myself wondering why using inheritance at all, since it's its sole interesting use (imo).</p> <p>Instead, in C++, you can use:</p> <ul> <li>Composition, for code reuse</li> <li>Free functions (defined in their own namespace)</li> <li><code>using</code>, <code>typedef</code> etc... to bring objects from outside the class</li> </ul> <p>Your example seems constrained here, but I too wrap my enums into <code>struct</code> to prevent namespace pollution by a thousand symbols (and because <code>struct</code> can be used as template parameters wheres namespaces cannot).</p> <pre><code>struct MyEnum { enum type { value }; }; class Child { public: typedef MyEnum::type Enum; Child(Enum e = MyEnum::value); private: }; </code></pre> <p>I don't see anything wrong with qualifying the name, instead I feel it makes it easier to read again, since you know which enum we are talking about...</p> <p>Really, <code>private</code> inheritance is best avoided (and usually replaced by Composition). The only valid case (imo) is for Empty Base Optimization... and frankly it's not often you need it (as usual with optimizations).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload