“C#基类虚函数” - “在Managed C ++ ref class中重写”

时间:2010-09-24 02:37:05

标签: c# c++ virtual override managed

我有一个.NET_4托管C ++引用类,它派生自用C#编写的.NET_4基类。

C#基类:

namespace Core
{
  public class ResourceManager
  {
    public class _Resource
    {
      public virtual void Delete() {}
    }
  }
}

托管C ++类:

namespace Input.DI
{
  public ref class Mouse : ResourceManager::_Resource
  {
    public:
    virtual void Delete() {}
  };
}

这是我得到的错误:

  

'Input :: DI :: Mouse :: Delete':匹配base ref class方法'Core :: ResourceManager :: _ Resource :: Delete',但未标记为'new'或'override';假设'new'(和'virtual')

从C#类覆盖virtual函数的正确托管C ++语法是什么?

1 个答案:

答案 0 :(得分:6)

你放override after the function signature

//MANAGED C++ CLASS
namspace Input.DI
{
  public ref class Mouse : ResourceManager::_Resource
  {
    public:
    virtual void Delete() override {}
  };
}