__abstract

备注

本主题仅适用于托管扩展的 1 版 C++ 的。只应在此语法维护 1 版代码。有关使用等效功能的信息在新语法,请参见 摘要 (Visual C++)

声明不能直接实例化的托管类。

__abstract class-specifier
__abstract struct-specifier

备注

__abstract 关键字声明目标类只能用作其他类的基类。 应用 __abstract 于类或结构不意味着该结果是 __gc 类或 __gc 结构。

不同于 摘要 基类的 C++ 概念,使用 __abstract 关键字的类可以定义其成员函数。

备注

__abstract 关键字不允许的,当使用 __value 或 __sealed 关键字和冗余,当使用 __interface 关键字。

示例

在下面的示例中, Derived 类从抽象基类 (Base) 派生。 实例化两个然后将尝试,但是,仅 Derived 成功。

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

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

__gc class Derived: public Base {};

int main() {
   Base* MyBase = new Base();   // C3622 can't BAse is abstract
   Derived* MyDerived = new Derived();
}