Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

abstract (Visual C++)

abstract is a context sensitive keyword that can indicate:

  • A member can only be defined in a derived type.

  • A type cannot be instantiated (can only act as a base type).

Marking a function abstract is the same as making it a pure virtual function. Making a member function abstract causes the enclosing class to also be marked abstract.

abstract is also valid when compiling for native targets (without /clr).

See Override Specifiers and Native Compilations for more information.

You can detect at compile time if a type is abstract with __is_abstract(type). For more information, see Compiler Support for Type Traits.

abstract is a context-sensitive keyword; see Context-Sensitive Keywords for more information.

The following sample will generate an error because class X is marked abstract.

// abstract_keyword.cpp
// compile with: /clr
ref class X abstract {
   virtual void f() {}

int main() {
   X ^ MyX = gcnew X;   // C3622

The following code example generates an error because it instantiates a native class that is marked abstract. This error will occur with or without the /clr compiler option.

// abstract_keyword_2.cpp
class X abstract {
   virtual void f() {}

int main() {
   X * MyX = new X; // C3622: 'X': a class declared as 'abstract'
                    // cannot be instantiated. See declaration of 'X'}

The following sample will generate an error because function f is marked abstract.

// abstract_keyword_3.cpp
// compile with: /clr
ref class X {
   virtual void f() abstract {}   // C3634
   virtual void g() = 0 {}   // C3634

Compiler option: /clr

Community Additions

© 2015 Microsoft