class blah
{
int g;
public:
void modg(int a){ g = a; }
int getg(){ return g; }
};
class foo
{
int h;
public:
blah *Goo;
foo(){
Goo = new blah;
Goo->modg(h);
};
void modh(int a){ h = a; }
int geth(){ return h; }
};
int main(int argc, char *argv[])
{
foo cl;
cl.modh(15);
cl.Goo->modg(cl.geth());
cout << cl.Goo->getg() << endl;
cl.modh(4);
cl.Goo->modg(cl.geth());
cout << cl.Goo->getg() << endl;
cl.modh(10);
cl.Goo->modg(cl.geth());
cout << cl.Goo->getg() << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Quick question (basic class/pointers stuff)
Hello y'all, i just wanna know,
if i have say:
just as an example, is cl.Goo->modg(int)
changing the real instance of cl.Goo class,
or just modifying a copy of it. I think from the test i did on this, it modifies the real thing.
This applies to my game engine, where before passing control of the program to the window, it passes a pointer to the game engine itself so i can access/change game data from within the window. I think this will work but I don't want any surprises x.X
That is changing the internal state of the blah that the Goo member points at, but continuing to point at the same blah.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement