From Jason Turner

[class.abstract]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpj_g2lj9n/{from.md → to.md} +29 -31
tmp/tmpj_g2lj9n/{from.md → to.md} RENAMED
@@ -1,25 +1,30 @@
1
- ## Abstract classes <a id="class.abstract">[[class.abstract]]</a>
2
 
3
  [*Note 1*: The abstract class mechanism supports the notion of a
4
  general concept, such as a `shape`, of which only more concrete
5
  variants, such as `circle` and `square`, can actually be used. An
6
  abstract class can also be used to define an interface for which derived
7
  classes provide a variety of implementations. — *end note*]
8
 
9
- An *abstract class* is a class that can be used only as a base class of
10
- some other class; no objects of an abstract class can be created except
11
- as subobjects of a class derived from it. A class is abstract if it has
12
- at least one *pure virtual function*.
13
 
14
  [*Note 2*: Such a function might be inherited: see
15
  below. — *end note*]
16
 
17
- A virtual function is specified *pure* by using a *pure-specifier* (
18
- [[class.mem]]) in the function declaration in the class definition. A
19
- pure virtual function need be defined only if called with, or as if
20
- with ([[class.dtor]]), the *qualified-id* syntax ([[expr.prim]]).
 
 
 
 
 
 
21
 
22
  [*Example 1*:
23
 
24
  ``` cpp
25
  class point { ... };
@@ -33,43 +38,36 @@ public:
33
  };
34
  ```
35
 
36
  — *end example*]
37
 
38
- [*Note 3*: A function declaration cannot provide both a
39
- *pure-specifier* and a definition — *end note*]
40
 
41
  [*Example 2*:
42
 
43
  ``` cpp
44
  struct C {
45
- virtual void f() = 0 { }; // ill-formed
46
  };
47
  ```
48
 
49
  — *end example*]
50
 
51
- An abstract class shall not be used as a parameter type, as a function
52
- return type, or as the type of an explicit conversion. Pointers and
53
- references to an abstract class can be declared.
54
-
55
- [*Example 3*:
56
-
57
- ``` cpp
58
- shape x; // error: object of abstract class
59
- shape* p; // OK
60
- shape f(); // error
61
- void g(shape); // error
62
- shape& h(shape&); // OK
63
- ```
64
-
65
- — *end example*]
66
 
67
  A class is abstract if it contains or inherits at least one pure virtual
68
  function for which the final overrider is pure virtual.
69
 
70
- [*Example 4*:
71
 
72
  ``` cpp
73
  class ab_circle : public shape {
74
  int radius;
75
  public:
@@ -93,15 +91,15 @@ public:
93
  would make class `circle` non-abstract and a definition of
94
  `circle::draw()` must be provided.
95
 
96
  — *end example*]
97
 
98
- [*Note 4*: An abstract class can be derived from a class that is not
99
  abstract, and a pure virtual function may override a virtual function
100
  which is not pure. — *end note*]
101
 
102
  Member functions can be called from a constructor (or destructor) of an
103
- abstract class; the effect of making a virtual call ([[class.virtual]])
104
- to a pure virtual function directly or indirectly for the object being
105
  created (or destroyed) from such a constructor (or destructor) is
106
  undefined.
107
 
 
1
+ ### Abstract classes <a id="class.abstract">[[class.abstract]]</a>
2
 
3
  [*Note 1*: The abstract class mechanism supports the notion of a
4
  general concept, such as a `shape`, of which only more concrete
5
  variants, such as `circle` and `square`, can actually be used. An
6
  abstract class can also be used to define an interface for which derived
7
  classes provide a variety of implementations. — *end note*]
8
 
9
+ A virtual function is specified as a *pure virtual function* by using a
10
+ *pure-specifier* [[class.mem]] in the function declaration in the class
11
+ definition.
 
12
 
13
  [*Note 2*: Such a function might be inherited: see
14
  below. — *end note*]
15
 
16
+ A class is an *abstract class* if it has at least one pure virtual
17
+ function.
18
+
19
+ [*Note 3*: An abstract class can be used only as a base class of some
20
+ other class; no objects of an abstract class can be created except as
21
+ subobjects of a class derived from it ([[basic.def]],
22
+ [[class.mem]]). — *end note*]
23
+
24
+ A pure virtual function need be defined only if called with, or as if
25
+ with [[class.dtor]], the *qualified-id* syntax [[expr.prim.id.qual]].
26
 
27
  [*Example 1*:
28
 
29
  ``` cpp
30
  class point { ... };
 
38
  };
39
  ```
40
 
41
  — *end example*]
42
 
43
+ [*Note 4*: A function declaration cannot provide both a
44
+ *pure-specifier* and a definition. — *end note*]
45
 
46
  [*Example 2*:
47
 
48
  ``` cpp
49
  struct C {
50
+ virtual void f() = 0 { }; // error
51
  };
52
  ```
53
 
54
  — *end example*]
55
 
56
+ [*Note 5*: An abstract class type cannot be used as a parameter or
57
+ return type of a function being defined [[dcl.fct]] or called
58
+ [[expr.call]], except as specified in [[dcl.type.simple]]. Further, an
59
+ abstract class type cannot be used as the type of an explicit type
60
+ conversion ([[expr.static.cast]], [[expr.reinterpret.cast]],
61
+ [[expr.const.cast]]), because the resulting prvalue would be of abstract
62
+ class type [[basic.lval]]. However, pointers and references to abstract
63
+ class types can appear in such contexts. — *end note*]
 
 
 
 
 
 
 
64
 
65
  A class is abstract if it contains or inherits at least one pure virtual
66
  function for which the final overrider is pure virtual.
67
 
68
+ [*Example 3*:
69
 
70
  ``` cpp
71
  class ab_circle : public shape {
72
  int radius;
73
  public:
 
91
  would make class `circle` non-abstract and a definition of
92
  `circle::draw()` must be provided.
93
 
94
  — *end example*]
95
 
96
+ [*Note 6*: An abstract class can be derived from a class that is not
97
  abstract, and a pure virtual function may override a virtual function
98
  which is not pure. — *end note*]
99
 
100
  Member functions can be called from a constructor (or destructor) of an
101
+ abstract class; the effect of making a virtual call [[class.virtual]] to
102
+ a pure virtual function directly or indirectly for the object being
103
  created (or destroyed) from such a constructor (or destructor) is
104
  undefined.
105