質問

Incomplete types cannot be instantiated, and abstract classes (that is, those with pure virtual member functions) also cannot be instantiated.

struct incomplete_type;

struct abstract_class
{
   virtual void foo() = 0;
};

By any chance are abstract classes themselves considered to be incomplete types?

役に立ちましたか?

解決

No!

Superficially they are similar (beyond the fact that abstract classes do have definitions whereas incomplete types do not):

[n3690: 3.9/5]: [..] Objects shall not be defined to have an incomplete type.

[n3690: 10.4/2]: An abstract class is a class that can be used only as a base class of some other class; no objects of an abstract class can be created except as subobjects of a class derived from it. [..]

[n3690: 10.4/3]: An abstract class shall not be used as a parameter type, as a function return type, or as the type of an explicit conversion. Pointers and references to an abstract class can be declared.

However, the standard in fact makes clear that the two concepts are unrelated:

[n3690: 3.9/5]: A class that has been declared but not defined, an enumeration type in certain contexts (7.2), or an array of unknown size or of incomplete element type, is an incompletely-defined object type. Incompletely-defined object types and the void types are incomplete types (3.9.1). Objects shall not be defined to have an incomplete type.

Your abstract class has a definition, and therefore cannot be considered to be an incomplete type.


N3690 is the C++14 Committee Draft.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top