English 中文(简体)
1. 封闭式带体的虚拟方法[封闭式]
原标题:Virtual methods without body in a sealed class [closed]

当我试图操作以下法典时,错误。

private sealed class ReqHandler 
{
    public ReqHandler(object @object, IntPtr method);

    public virtual IAsyncResult BeginInvoke(object[] args, AsyncCallback callback, object @object);

    public virtual d0 EndInvoke(IAsyncResult result);

    public virtual d0 Invoke(object[] args);
}

我发现的错误是。

HB_Auth.AuthImpl.ReqHandler.ReqHandler(object, IntPtr) must have a body because it is not marked abstract, extern, or partial (CS0501) (HB_Auth.Patched)

New virtual member HB_Auth.AuthImpl.ReqHandler.BeginInvoke(object[], AsyncCallback, object) is declared in a sealed classHB_Auth.AuthImpl.ReqHandler (CS0549) (HB_Auth.Patched)

问题回答

The compiler error says it all: You have declared methods, but they do not have a body. So, either give them a body, ar mark them as abstract. However, as I see that your class is private and sealed, making them abstract is a no-go, as your class is sealed, so nobody can inherit from it.

但是,你所遵循的法典,像不完善的法典一样?

  • You can t have virtual members in a sealed class.

<>strong>CS0549 Error:

不能将密封等级用作基类,而虚拟方法必须在衍生类别中实施,这自相矛盾。

MSDN

  • The functions need to be implemented:

<>strong>CS0501 Error:

无<条码>指示方法必须有执行。

MSDN

您可能希望将<条码>保护和<条码>/条码>的功能<条码>。

First problem: constructors need a body. You can t just declare a constructor, you need to define it. You can use an empty constructor if you want:

public ReqHandler(object @object, IntPtr method) {}

第二个问题:你是密封的,但拥有虚拟方法。 虚拟方法仅存在于扩大这一类的班级中,但可以延伸一个密封的班级,因此错误。 你们要么需要界定这些方法,要么不使用这些方法(在这种情况下,你需要将其扩大到做任何有用的事情)。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签