This commit is contained in:
Bjarne Stroustrup
2017-04-18 21:27:30 -04:00
parent 6987bfd2f0
commit cfa2fec1f2

View File

@@ -63,20 +63,20 @@ Supporting sections:
You can sample rules for specific language features: You can sample rules for specific language features:
* assignment: * assignment:
[and regular types](#Rc-regular) -- [regular types](#Rc-regular) --
[prefer initialization](#Rc-initialize) -- [prefer initialization](#Rc-initialize) --
[copy semantics](#Rc-copy-semantics) -- [copy](#Rc-copy-semantics) --
[move semantics](#Rc-move-semantics) -- [move](#Rc-move-semantics) --
[and other operations](Rc-matched) -- [other operations](Rc-matched) --
[default](#Rc-eqdefault) [default](#Rc-eqdefault)
* `class`: * `class`:
[data](#Rc-org) -- [data](#Rc-org) --
[invariant](#Rc-struct) -- [invariant](#Rc-struct) --
[members](#Rc-member) -- [members](#Rc-member) --
[helper functions](#Rc-helper) -- [helpers](#Rc-helper) --
[concrete types](#SS-concrete) -- [concrete types](#SS-concrete) --
[constructors, assignments, and destructors](#S-ctor) -- [ctors, assignments, and dtorss](#S-ctor) --
[hierarchies](#SS-hier) -- [hierarchy](#SS-hier) --
[operators](#SS-overload) [operators](#SS-overload)
* `concept`: * `concept`:
[rules](#SS-concepts) -- [rules](#SS-concepts) --
@@ -86,20 +86,20 @@ You can sample rules for specific language features:
* constructor: * constructor:
[invariant](#Rc-struct) -- [invariant](#Rc-struct) --
[establish invariant](#Rc-ctor) -- [establish invariant](#Rc-ctor) --
[`throw` in constructor](#Rc-throw) -- [`throw`](#Rc-throw) --
[default](#Rc-default0) -- [default](#Rc-default0) --
[not needed](#Rc-default) -- [not needed](#Rc-default) --
[`explicit`](#Rc-explicit) -- [`explicit`](#Rc-explicit) --
[delegating](#Rc-delegating) -- [delegating](#Rc-delegating) --
[and `virtual`](#RC-ctor-virtual) [`virtual`](#RC-ctor-virtual)
* derived `class`: * derived `class`:
[when to use](#Rh-domain) -- [when to use](#Rh-domain) --
[as interface](#Rh-abstract) -- [as interface](#Rh-abstract) --
[and destructors](#Rh-dtor) -- [destructors](#Rh-dtor) --
[copy](#Rh-copy) -- [copy](#Rh-copy) --
[getters and setters](#Rh-get) -- [getters and setters](#Rh-get) --
[multiple inheritance](#Rh-mi-interface) -- [multiple inheritance](#Rh-mi-interface) --
[overloading member functions](#Rh-using) -- [overloading](#Rh-using) --
[slicing](#Rc-copy-virtual) -- [slicing](#Rc-copy-virtual) --
[`dynamic_cast`](#Rh-dynamic_cast) [`dynamic_cast`](#Rh-dynamic_cast)
* destructor: * destructor:
@@ -123,10 +123,10 @@ You can sample rules for specific language features:
* function: * function:
[naming](#Rf-package) -- [naming](#Rf-package) --
[single operation](#Rf-logical) -- [single operation](#Rf-logical) --
[may not throw](#Rf-noexcept) -- [no throw](#Rf-noexcept) --
[arguments](#Rf-smart) -- [arguments](#Rf-smart) --
[argument passing](#Rf-conventional) -- [argument passing](#Rf-conventional) --
[multiple return values](#Rf-out-multi) [multiple return values](#Rf-out-multi) --
[pointers](#Rf-return-ptr) -- [pointers](#Rf-return-ptr) --
[lambdas](#Rf-capture-vs-overload) [lambdas](#Rf-capture-vs-overload)
* `inline`: * `inline`:
@@ -6929,19 +6929,53 @@ or various bases from boost.intrusive (e.g. `list_base_hook` or `intrusive_ref_c
##### Reason ##### Reason
??? Allow separation of shared data and interface.
To avoid all shared data to being put into an ultimate base class.
##### Example ##### Example
??? struct Interface {
virtual void f();
virtual int g();
// ... no data here ...
};
class Utility { // with data
void utility1();
virtual void utility2(); // customization point
public:
int x;
int y;
};
class Derive1 : public Interface, protected Utility {
// overrride Iterface functions
// Maybe overrid Utility virtual functions
// ...
};
class Derive2 : public Interface, protected Utility {
// overrride Iterface functions
// Maybe overrid Utility virtual functions
// ...
};
Factoring out `Utility` makes sense if many derived classes share significent "implementation details."
##### Note ##### Note
??? Obviously, the example is too "theoretical", but it is hard to find a *small* realistic example.
`Interface` is the root of an [interface hierarchy](#Rh-abstract)
and `Utility` is the root of an [implementation hierarchy](Rh-kind).
##### Note
Often, lineraization of a hierarchy is a better solution.
##### Enforcement ##### Enforcement
??? Flag mixed interface and implementation hierarchies.
### <a name="Rh-using"></a>C.138: Create an overload set for a derived class and its bases with `using` ### <a name="Rh-using"></a>C.138: Create an overload set for a derived class and its bases with `using`