description | title | ms.date | ms.topic | helpviewer_keywords | ms.assetid | |
---|---|---|---|---|---|---|
Learn more about: new (new slot in vtable) (C++/CLI and C++/CX) | new (new slot in vtable) (C++/CLI and C++/CX) | 10/12/2018 | reference |
| 1a9a5704-f02f-46ae-ad65-f0f2b6dbabc3 |
The new
keyword indicates that a virtual member will get a new slot in the vtable.
(There are no remarks for this language feature that apply to all runtimes.)
Not supported in Windows Runtime.
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:
xref:System.Reflection.MethodInfo.GetBaseDefinition?displayProperty=nameWithType
xref:System.Reflection.MethodAttributes?displayProperty=nameWithType
Compiler option: /clr
The following sample shows the effect of new
.
// newslot.cpp// compile with: /clr ref classC { public:virtualvoidf() { System::Console::WriteLine("C::f() called"); } virtualvoidg() { System::Console::WriteLine("C::g() called"); } }; ref classD : publicC { public:virtualvoidf() new { System::Console::WriteLine("D::f() called"); } virtualvoidg() override { System::Console::WriteLine("D::g() called"); } }; ref classE : publicD { public:virtualvoidf() override { System::Console::WriteLine("E::f() called"); } }; intmain() { 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 }
C::f() called D::f() called D::g() called D::g() called E::f() called