CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2010
    Posts
    907

    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,654

    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
    https://visualstudio.microsoft.com/vs

  3. #3
    Join Date
    Dec 2010
    Posts
    907

    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
  •  





Click Here to Expand Forum to Full Width

Featured