Topic: Problem: initialization of references in classes
Author: kingsum@pdx809.pdx502.intel.com (Kingsum Chow)
Date: Sat, 21 Aug 1993 00:16:41 GMT Raw View
I have failed to find a satisfactory answer for the following
problem. Please help by suggesting an explanation for it or
a way to work around it. THanks!
class A {
public:
int a;
...
};
struct B {
int& b;
...
B(int& intref) : b(intref) { ... }
};
class C : public A {
public:
B x;
...
C() : x(a) { ... }
};
The problem is with our Objectworks Cfront C++ compiler,
`the address of a' is stored in b, instead of b sharing
the content with a using the same address.
--Kingsum
--
summer: kingsum@ichips.intel.com
school: kingsum@cs.washington.edu
Author: joe@bftsi0.UUCP (Joe Foster of Borg)
Date: 21 Aug 93 10:49:23 GMT Raw View
In article <KINGSUM.93Aug20161641@pdx809.pdx502.intel.com>, kingsum@pdx809.pdx502.intel.com (Kingsum Chow) writes:
: I have failed to find a satisfactory answer for the following
: problem. Please help by suggesting an explanation for it or
: a way to work around it. THanks!
: class A {
: public:
: int a;
: ...
: };
: struct B {
: int& b;
: ...
: B(int& intref) : b(intref) { ... }
: };
: class C : public A {
: public:
: B x;
: ...
: C() : x(a) { ... }
: };
: The problem is with our Objectworks Cfront C++ compiler,
: `the address of a' is stored in b, instead of b sharing
: the content with a using the same address.
Sorry, that's how references are defined. '&' is just good old
'*' in disguise. If a B needs to know where to find an integer,
it has to store the address of that integer someplace. Perhaps
if you told us *why* this is unsatisfactory, a better solution
can be found.
Joe Foster
joe@bftsi0.uucp