CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2002
    Location
    WA
    Posts
    223

    A stupid error: An object reference required for the nonstatic field, method, or prop

    IT DRIVES ME NUTS!!! *** IS WRONG?


    PHP Code:
    public ETMETMHandler _handler ): base( new ETHandler(OnTarg) ) 
    It *****es at the line above, however it's fine with:

    PHP Code:
    public ETMETMHandler _handler ): basenull 
    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)

  2. #2
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125
    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.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  3. #3
    Join Date
    Jan 2002
    Location
    WA
    Posts
    223
    If I do this.OnTarg
    it gives me another error - can't use this in that place

  4. #4
    Join Date
    Oct 2001
    Location
    Norway
    Posts
    265
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured