Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All



This topic applies only to version 1 of Managed Extensions for C++. This syntax should only be used to maintain version 1 code. See sealed for information on using the equivalent functionality in the new syntax.

Prevents a method from being overridden or a class from being a base class.

__sealed class-specifier
__sealed struct-specifier
__sealed function-declarator

The __sealed keyword specifies that a class method cannot be overridden or that a class cannot be a base class.

When using the __sealed keyword, keep the following points in mind:

  • A __sealed virtual method cannot be overridden.

  • If a nonvirtual member method is marked __sealed, the __sealed qualification is ignored.

  • A __sealed method cannot be pure.

  • The __sealed keyword is not allowed when used with the __interface keyword.

When a class (or struct) is marked with __sealed, the class cannot be used as a base class. For example:

__sealed __gc class A {
   // ...
// error: cannot derive from a sealed class
__gc class B : public A { /* ...*/ };

The __sealed keyword is not allowed when used with the __abstract keyword.

In the following example, a sealed virtual method (f) is declared. The function is then overridden in main(), causing a compiler error:

// keyword__sealed.cpp
// compile with: /clr:oldSyntax

#using <mscorlib.dll>
extern "C" int printf_s(const char*, ...);

__gc struct I
    __sealed virtual void f()
    virtual void g()

__gc struct A : I 
    void f() // C3248 sealed function
    void g()

int main()
    A* pA = new A;


Community Additions

© 2015 Microsoft