Jun. 11th, 2006

mrlachatte: (Default)
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 :(

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. 7th, 2025 05:23 am
Powered by Dreamwidth Studios