Export (0) Print
Expand All
1 out of 3 rated this helpful - Rate this topic

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 {
public:
   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 {
public:
   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 {
public:
   virtual void f() abstract {}   // C3634
   virtual void g() = 0 {}   // C3634
};

Compiler option: /clr

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.