编译器警告(等级 4)C4487

“derived_class_function”:匹配继承的非虚拟方法“base_class_function”,但未显式标记为“new”

派生类中的函数与非虚拟基类函数具有相同的签名。 C4487 提醒你,派生类函数不会替代基类函数。 显式将派生类函数标记为 new 以解析此警告。

有关详细信息,请参阅 new(vtable 中的新插槽)

示例

以下示例生成 C4487。

// C4487.cpp
// compile with: /W4 /clr
using namespace System;
public ref struct B {
   void f() { Console::WriteLine("in B::f"); }
   void g() { Console::WriteLine("in B::g"); }
};

public ref struct D : B {
   void f() { Console::WriteLine("in D::f"); }   // C4487
   void g() new { Console::WriteLine("in D::g"); }   // OK
};

int main() {
   B ^ a = gcnew D;
   // will call base class functions
   a->f();
   a->g();
}