__abstract
Collapse the table of content
Expand the table of content
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. ArchiveDisclaimer

__abstract

Visual Studio .NET 2003

Declares a managed class that cannot be instantiated directly.

__abstract class-specifier
__abstract struct-specifier

Remarks

The __abstract keyword declares that the target class can only be used as a base class of another class. Applying __abstract to a class or structure does not imply that the result is a __gc class or __gc structure.

Differing from the C++ notion of an abstract base class, a class with the __abstract keyword can define its member functions. For more information on __abstract, see 17 __abstract keyword.

Note   The __abstract keyword is not allowed when used with the __value or __sealed keyword and redundant when used with the __interface keyword.

Example

In the following example, the Derived class is derived from an abstract base class (Base). Instantiation is then attempted on both, but only Derived is successful.

// keyword__abstract.cpp
// compile with: /clr
#using <mscorlib.dll>

__abstract __gc class Base
{
   int BaseFunction() { return 0; }
};

__gc class Derived: public Base
{
};

int main()
{
   Base* MyBase = new Base(); // C3622 Error: cannot instantiate an abstract class
   Derived* MyDerived = new Derived();
   return 0;
}

See Also

Managed Extensions for C++ Reference | __value | Delegates in Managed Extensions for C++ | C++ Keywords

Show:
© 2016 Microsoft