mrlachatte: (Default)
[personal profile] mrlachatte
Riddle me this.  I've got defitinitions like this:

--------------

class State
{
    private:
       GUI *gui;
       std::map<char *, int> iVars;

    public:
       State()
       {
          set_ivar("test", 1);
          gui = new GUI(this);
       }

       void set_ivar(char *name, int value)
       {
          iVars[name] = value;
       }

       int get_ivar(char *name)
       {
          if(iVars[name])
             return iVars[name];
          else return 0;
       }
};

class GUI
{
    public:
       GUI(State *s)
       {
          printf("value is %d", s->get_ivar("test"));
       }
};

----------

Now, ignoring the nice circular dependency going on there, explain why I would get a 0 in the printf() in the GUI constructor.  The real problematic code is more complex, but I've tested, and the values in the map<> are valid before the call to create the GUI.  However, inside the GUI constructor, suddenly they don't exist anymore.  Help :(

Date: 2006-06-12 03:08 am (UTC)
From: [identity profile] inmatarian.livejournal.com
Wow, shows what I know. I looked at it for a few minutes and couldn't figure it out. F'ing Lua messing with my understanding of associative containers.

An alternate fix would be to have a const char * str_test = "test"; in a common scope between them and use the str_test identifier.

December 2007

S M T W T F S
      1
2345678
9101112131415
16171819202122
23242526 272829
3031     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 13th, 2025 12:27 pm
Powered by Dreamwidth Studios