Click to See Complete Forum and Search --> : A stupid error: An object reference required for the nonstatic field, method, or prop


Silver Ghost
December 12th, 2002, 11:52 PM
IT DRIVES ME NUTS!!! *** IS WRONG?


public ETM( ETMHandler _handler ): base( new ETHandler(OnTarg) )

It *****es at the line above, however it's fine with:

public ETM( ETMHandler _handler ): base( null )

OnTarget is declared inside of that same class, it's a method, and it's not static. What the **** does it ***** about?

(please forgive my foul language, but I am freaking mad)

TheCPUWizard
December 12th, 2002, 11:55 PM
Simple.

You can not use a non-static member function in this way. Member functions need an object reference (i.e. This Pointer), you are not supplying one.

hint: It seems you want/need a delegate.

Silver Ghost
December 13th, 2002, 01:10 AM
If I do this.OnTarg
it gives me another error - can't use this in that place

Arild Fines
December 13th, 2002, 02:51 AM
There are certain limitations on what you can call in a base class initializer. For one, the object is not yet fully constructed, so you don't have access to the this pointer.