changing values for one class and showing it ..!

hi all,

this is a pure c++ class problem , i am not good with pointers and it seems somehow pointers should be used,...pls see the problem below..

i have three classes named super ,child1 and child2..

#include "child1.h"
#include "child2.h"

class super
{
private:
int record_clicks;
..
child1 *myChild1;
child2 *myChild2;
..
};
class child1
{
..
private:
int record_clicks;
..
}
class child2
{
..
private:
int record_clicks;
..
}
the problem i am facing is that that when i change the value in child1->recordClick i wanted to see the changed value in child2->recordClick, i make a function for that which passes the value of recordClick to TrainingUI which then passes this value to child2,but now if i wanted to change the value in child2->recordClick and show it on child1->recordClick ...how can i do that i mean how to change recordClicks value in both direction..i hope u undertsand
So you want both 'record_clicks' to be changed when you change just one, right? You'd need to make both 'record_clicks' pointers to int and initialize them like this:
1
2
myChild1->record_clicks=new int;
myChild2->record_clicks=myChild1->record_clicks;

Now a change to either *record_clicks will be reflected on both classes.

I'm curious about your design. Do you really need a child1 class and a child2 class? Wouldn't a single child class be enough?
hi..
thanks for the reply ,i am basically using qt ,if you want to look at what my original i mean real problem is you can visit this link..
http://www.qtcentre.org/forum/f-general-programming-9/t-how-to-infrom-a-different-class-of-a-change-in-variable-15417.html
Topic archived. No new replies allowed.