Partager via


abstract (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).

Remarks

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.

Example

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

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

int main() {
   X ^ MyX = gcnew X;   // C3622 cannot instantiate abstract class
}

The following sample shows that the compiler will generate an error because a native class is marked abstract, when compiled with /clr.

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

int main() {
   X * MyX = new X;   // C3622
}

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

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

See Also

Concepts

New C++ Language Features