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