分享方式:


編譯器警告 (層級 4) C4487

'derived_class_function':符合繼承的非虛擬方法 'base_class_function',但未明確標示為 'new'

衍生類別中的函式具有與非虛擬基類函式相同的簽章。 C4487 提醒您,衍生類別函式不會覆寫基類函式。 將衍生類別函式明確標示為 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();
}