Hello people
My problem: getting a reference to a variable works, getting to a vector
position, don't.
I'm writing a pool game, that is a school assignment. And there's a
strange behavior, that only makes me think it's a compiler error - just
a side note, I'm using gcc version 3.2.3 (mingw special 20030504-1), I
downloaded a few days ago.
So, here's the problem: I have two classes to deal: Bola (ball) and Taco
(the direction the white ball will go).
This is the ball class:
--------
class Bola {
...
double x, y, z;
public:
...
double get_x() const { return x; }
... and the same for y and z
};
---------
And the class Taco receives a Bola reference:
----
class Taco {
const Bola& bola;
public:
Taco(const Bola& b): bola(b) { }
}
----
You see, the Taco object will receive a reference to a Bola object, and
use the get_* functions to know the ball coordinates. It all works fine
if I do this:
---
Bola ball(...);
Taco taco(ball);
---
BUT if I use a vector<>, it doesn't work:
---
vector<Bola> balls;
ball.push_back(Bola(...));
Taco taco(balls[0]);
---
In this case, the functions get_x, get_y and get_z always return the
same values; what I get then is an arrow (drawn by Taco) that is always
in (0, 0, 0), the initial ball position, and not following the ball when
it moves. In the first case, all works fine, the arrow is drawn in the
same position as the ball.
If anyone wanna try, my code is here:
http://www.polarhome.com/~danielko/pool/Sinuca.zip
and the sources, in html, here:
http://www.polarhome.com/~danielko/pool/html
I would be glad if anyone could tell my why with a normal variable it
works, and not witha a vector position.
Thanks in advance
Daniel K. O.
|