rihaczek@jellosub.luftfahrt.uni-stuttgart.de (Clemens Rihaczek) (05/16/91)
Hi, there!
Sorry, I've only recently started programming in C++, so this might
be a stupid question. Anyway, here is an attempt to describe my problem:
Say, there are two classes, one called Object (just some plain-vanilla
class) and one called ObjectArray (hosting an array of pointers to instances
of class Object). This is what they might look like:
class Object
{
inline double& ObjVal() { return obj_val; }
...
double obj_val;
}
class ObjectArray
{
inline Object*& operator[](unsigned int index) { return elements[index]; }
...
Object* * elements;
}
Now, when I use the following piece of code on an Apollo DN10000,
ObjectArray oa(...);
oa[i]->ObjVal() = ....;
oa[i]'s obj_val member turns out to have some crud value like 2.277e-308
(smallest double?). Turning off the optimizer helps a little, the values
become slightly 'more reasonable', but, hey -- junk is junk.
Introducing a dummy variable op (an Object pointer)
ObjectArray oa(...);
Object* op;
op = oa[i];
op->ObjVal() = ....;
solves the problem and the contents of the obj_val member reads ok.
Both versions work fine on an Apollo DN3500.
*** WHY? ***
Please excuse my ignorance, conserve energy (no flames...)
--
Clemens Rihaczek ISD (Department for Statics and
Dynamics of Aerospace Structures)
University of Stuttgart
Pfaffenwaldring 27
fax: +49 711-685-3706 7000 Stuttgart 80, West Germany.
voice: +49 711-685-3899
Internet: rihaczek@dogmatix.luftfahrt.uni-stuttgart.de (129.69.110.10)