Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Good nice question. I really wish that the Standard was a little more explicit about what the intended usage is. Maybe there should be a C++ Rationale document that sits alongside the language standard. In any case, here is the approach that I use:</p> <p>(a) I'm not aware of the existence of any such list. Instead, I use the following list to determine whether a Standard Library type is likely to be designed to be inherited from:</p> <ul> <li>If it doesn't have any <code>virtual</code> methods, then you shouldn't be using it as a base. This rules out <code>std::vector</code> and the like.</li> <li>If it does have <code>virtual</code> methods, then it is a candidate for usage as a base class.</li> <li>If there are lots of <code>friend</code> statements floating around, then steer clear since there is probably an encapsulation problem.</li> <li>If it is a template, then look closer before you inherit from it since you can probably customize it with specializations instead.</li> <li>The presence of policy-based mechanism (e.g., <code>std::char_traits</code>) is a pretty good clue that you shouldn't be using it as a base.</li> </ul> <p>Unfortunately I don't know of a nice comprehensive or <em>black and white</em> list. I usually go by gut feel.</p> <p>(b) I would apply <a href="http://en.wikipedia.org/wiki/Liskov_substitution_principle" rel="noreferrer">LSP</a> here. If someone calls <code>what()</code> on your exception, then it's observable behavior should match that of <code>std::exception</code>. I don't think that it is really a standards conformance issue as much as a correctness issue. The Standard doesn't require that subclasses are substitutable for base classes. It is really just a <em>"best practice"</em>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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