Export (0) Print
Expand All

__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:
© 2014 Microsoft