mrlachatte: (Default)
mrlachatte ([personal profile] mrlachatte) wrote2006-06-11 08:38 pm
Entry tags:

Chapter 39: In which the STL comes out of the closet

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 :(

[identity profile] highlyeccentric.livejournal.com 2006-06-12 02:23 am (UTC)(link)
o josh, i'm begining to fear for your sanity...