# Quick question (basic class/pointers stuff)

## Recommended Posts

AAAP    137
Hello y'all, i just wanna know, if i have say:
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;
}


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

##### Share on other sites
Zahlman    1682
That is changing the internal state of the blah that the Goo member points at, but continuing to point at the same blah.

##### Share on other sites
AAAP    137
so it wouldn't be a copy, and it will affect the state of the program.

thats what I want o_O.

now.. im realizing that to do this, the Window class probably shouldn't be a member of the game class 0_0