Skip to content

Latest commit

 

History

History
126 lines (100 loc) · 2.79 KB

new-new-slot-in-vtable-cpp-component-extensions.md

File metadata and controls

126 lines (100 loc) · 2.79 KB
title new (new slot in vtable) (C++ Component Extensions) | Microsoft Docs
ms.custom
ms.date 11/04/2016
ms.reviewer
ms.suite
ms.technology
cpp-windows
ms.tgt_pltfrm
ms.topic language-reference
dev_langs
C++
helpviewer_keywords
new keyword [C++]
ms.assetid 1a9a5704-f02f-46ae-ad65-f0f2b6dbabc3
caps.latest.revision 20
author mikeblome
ms.author mblome
manager ghogen
translation.priority.ht
cs-cz
de-de
es-es
fr-fr
it-it
ja-jp
ko-kr
pl-pl
pt-br
ru-ru
tr-tr
zh-cn
zh-tw

new (new slot in vtable) (C++ Component Extensions)

The new keyword indicates that a virtual member will get a new slot in the vtable.

All Runtimes

(There are no remarks for this language feature that apply to all runtimes.)

Windows Runtime

Not supported in Windows Runtime.

Common Language Runtime

Remarks

In a /clr compilation, new indicates that a virtual member will get a new slot in the vtable; that the function does not override a base class method.

new causes the newslot modifier to be added to the IL for the function. For more information about newslot, see:

Requirements

Compiler option: /clr

Examples

Example

The following sample shows the effect of new.

// newslot.cpp  
// compile with: /clr  
ref class C {  
public:  
   virtual void f() {  
      System::Console::WriteLine("C::f() called");  
   }  
  
   virtual void g() {  
      System::Console::WriteLine("C::g() called");  
   }  
};  
  
ref class D : public C {  
public:  
   virtual void f() new {  
      System::Console::WriteLine("D::f() called");  
   }  
  
   virtual void g() override {  
      System::Console::WriteLine("D::g() called");  
   }  
};  
  
ref class E : public D {  
public:  
   virtual void f() override {  
      System::Console::WriteLine("E::f() called");  
   }  
};  
  
int main() {  
   D^ d = gcnew D;  
   C^ c = gcnew D;  
  
   c->f();   // calls C::f  
   d->f();   // calls D::f  
  
   c->g();   // calls D::g  
   d->g();   // calls D::g  
  
   D ^ e = gcnew E;  
   e->f();   // calls E::f  
}  

Output

C::f() called  
  
D::f() called  
  
D::g() called  
  
D::g() called  
  
E::f() called  

See Also

Component Extensions for Runtime Platforms
Override Specifiers