Skip to content

Latest commit

 

History

History
85 lines (61 loc) · 2.15 KB

how-to-declare-override-specifiers-in-native-compilations-cpp-cli.md

File metadata and controls

85 lines (61 loc) · 2.15 KB
description title ms.date helpviewer_keywords ms.assetid
Learn more about: How to: Declare Override Specifiers in Native Compilations (C++/CLI)
How to: Declare Override Specifiers (C++/CLI)
11/04/2016
override specifiers in native compilation, overriding
d0551836-9ac7-41eb-a6e9-a4b3ef60767d

How to: Declare Override Specifiers in Native Compilations (C++/CLI)

sealed, abstract, and override are available in compilations that do not use /ZW or /clr.

Note

The ISO C++11 Standard language has the override identifier and the final identifier, and both are supported in Visual Studio Use final instead of sealed in code that is meant to be compiled as native-only.

Example: sealed is valid

Description

The following example shows that sealed is valid in native compilations.

Code

// sealed_native_keyword.cpp
#include <stdio.h>
__interface I1 {
   virtual void f();
   virtual void g();
};

class X : public I1 {
public:
   virtual void g() sealed {}
};

class Y : public X {
public:

   // the following override generates a compiler error
   virtual void g() {}   // C3248 X::g is sealed!
};

Example: override is valid

Description

The next example shows that override is valid in native compilations.

Code

// override_native_keyword.cpp
#include <stdio.h>
__interface I1 {
   virtual void f();
};

class X : public I1 {
public:
   virtual void f() override {}   // OK
   virtual void g() override {}   // C3668 I1::g does not exist
};

Example: abstract is valid

Description

This example shows that abstract is valid in native compilations.

Code

// abstract_native_keyword.cpp
class X abstract {};

int main() {
   X * MyX = new X;   // C3622 cannot instantiate abstract class
}

See also

Override Specifiers