M
mlt
I have 3 classes A, B and C. A reference to B is passed to C from A:
class A {
private:
B b;
C c;
float time;
public:
void init() {
time = 0.00f;
// Pass a reference of b to c.
c.setup(b);
}
void run() {
// update B, why is this not visible in C??
b.update(time);
time +=0.001;
}
};
class B {
private:
float time;
public:
void update(float t){
time = t;
}
float getTime() {
time;
}
};
class C {
private:
B b;
public:
// Takes a reference to B
void setup(B & b_in) {
b = b_in;
}
void testB() {
std::cout << "time in b = " << b.getTime()<< std::endl;
}
};
As can be seen 'b' is modified/updated in A::run() which is called multiple
times. But when I call:
C::testB();
the updated time is not printed. Why are changes made in B from A not
visible in C?
class A {
private:
B b;
C c;
float time;
public:
void init() {
time = 0.00f;
// Pass a reference of b to c.
c.setup(b);
}
void run() {
// update B, why is this not visible in C??
b.update(time);
time +=0.001;
}
};
class B {
private:
float time;
public:
void update(float t){
time = t;
}
float getTime() {
time;
}
};
class C {
private:
B b;
public:
// Takes a reference to B
void setup(B & b_in) {
b = b_in;
}
void testB() {
std::cout << "time in b = " << b.getTime()<< std::endl;
}
};
As can be seen 'b' is modified/updated in A::run() which is called multiple
times. But when I call:
C::testB();
the updated time is not printed. Why are changes made in B from A not
visible in C?