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

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

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

System_CAPS_ICON_note.jpg Note

The new keyword has many uses and meanings. For more information, see the disambiguation topic new.

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

Not supported in Windows 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  

Component Extensions for Runtime Platforms
Override Specifiers

Show: