passing Pointers

Not sure how to do this right. a class called mClass. in mClass i have pointer of a cClass. and i also have a variable of bClass.

1
2
3
4
5
6
7
8
9
10
11
12
13
class mClass
{
private:
	cClass* cc;
        bClass bb;
};

mClass() :
	cc(new cClass(44)),
	bb(cc) //this is where the question starts
{
        //random code here
}


bClass will accept cc. and hold in a local pointer. When i make changes to cc inside of the mClass, i want bClass to see those changes automatically.
1
2
3
4
5
6
7
8
9
10
11
class bClass
{
private:
        cClass* cc2
};

bClass(cClass* c) :
	cc2(c)
{
        //random code here
}

is that the right way to handle this?
Last edited on
So you want m and b to point to the same thing. so mClass() : cc(new cClass(44)), bb(cc) {}
Last edited on
YES thanks for catching that mistake.

mClass will hold the variable cc. it will also hold the variable bb. it will then pass cc to bb.

cc will just be a data class that loads some data from a text file and holds it. multiple objects will be using this data. mClass is basically the MAIN class. its gonna hold the data (cc) and pass it to all the objects that needs to use and modify it (bb being one of those).

it may be confusing im just not sure how to explain it any better.

I think im getting the results i want. I just feel like I should be using references.
Last edited on
Topic archived. No new replies allowed.