Static call problems
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Static call problems

  1. #1
    Join Date
    Dec 2010
    Posts
    523

    Static call problems

    Code:
    class A
    {
       std::map<std::string, Unit*> aMap;
        class B
        {
             void doSomething()
             {
                  callA();
             }
        };
    
        void callA()
        {
            aMap.find().... 
        }
    };
    this code snippet results in "A non-static member reference must be made relative to a specific object"
    When I make callA() static, this error goes away, but there is problem with aMap.
    Sorry, I can't translate the message because the IDE is in my language.
    So please help me out.
    Thanks
    Jack

  2. #2
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,632

    Re: Static call problems

    The problem is that class B hasn't got a clue which object A that is suppossed to receive the callA call. Pass that information to B when you create it.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    http://www.microsoft.com/visualstudio/eng/downloads

  3. #3
    Join Date
    Dec 2010
    Posts
    523

    Re: Static call problems

    S_M_A
    I pass the object pointer to B, and it is working like a charm. Thanks a lot
    Jack

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center