0

When I try to run the following code it errors.

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);
}

The error that I get is.

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)

gdoron
  • 147,333
  • 58
  • 291
  • 367
user1388129
  • 9
  • 1
  • 3
  • 1
    C# is not C++: in C# the implementation goes into the class declaration. – Vlad May 10 '12 at 21:17
  • Two problems: virtual methods still need an implementation, and sealed classes cannot have virtual members. – gotopie May 10 '12 at 21:18
  • That doesn't seem like a 'basic C# program'. It's not basic, it's not (valid) C#, and it's not a program. – Kendall Frey May 10 '12 at 21:18
  • Are your errors compile errors or warnings? You can use pragma to disable warnings which you find annoying before a code block and then to turn them back on again.. Additionally see my comments below for possible options on how to move the virtual member but keep the declaration. [MSDN]http://msdn.microsoft.com/en-us/library/x74w198a.aspx – Jay May 10 '12 at 21:42
  • Your real solution is to pick up some basic C# tutorials. Our user base can't really teach you how to code C#. –  May 11 '12 at 13:01

3 Answers3

4

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.

But, the code that you've pasted, looks like decompiled code ?

Frederik Gheysels
  • 56,135
  • 11
  • 101
  • 154
  • 1
    it is decompiled not all of it just this bit is because i lost part of the source files when i lost my memory stick – user1388129 May 10 '12 at 21:38
3
  • You can't have virtual members in a sealed class.

CS0549 Error:

A sealed class cannot be used as a base class, and a virtual method has to be implemented in a derived class, which is a contradiction.

MSDN

  • The functions need to be implemented:

CS0501 Error:

Non abstract methods must have implementations.

MSDN

You probably want to make the class protected,and the virtual functions abstract

gdoron
  • 147,333
  • 58
  • 291
  • 367
1

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) {}

Second problem: you made a sealed class, but have virtual methods. Virtual methods exist solely for overriding in classes extending this class, but you can't extend a sealed class, therefore the error. You need to either define those methods, or unseal the class (in which case, you'll need to extend it to do anything useful).

kitti
  • 14,663
  • 31
  • 49
  • (nitpicking) virtual methods exist for a _possibility_ for late binding, i.e., possibility to be overridden: no problem if no dreived class overrides them. – Vlad May 10 '12 at 21:18
  • 1
    @Vlad True. But there still has to be a possibility, which there isn't with a sealed class. Damn nitpickers. ;P – kitti May 10 '12 at 21:19
  • http://stackoverflow.com/questions/155087/how-can-you-inherit-from-a-sealed-class-using-reflection-in-net Research says... "You can sneak virtual members into a sealed class by inserting them into a base class" – Jay May 10 '12 at 21:37
  • 1
    My objection was only against "Virtual methods exist solely for overriding", and not for the rest :-P – Vlad May 10 '12 at 22:28