rae@gpu.utcs.toronto.edu (Reid Ellis) (10/02/90)
When you are writing a constructor for a class, it is useful to
initialize any class objects your class continas like this:
X::X()
: location(12, 34), value(1.23), direction(X::dir())
{
// ...
}
Note that the arguments to constructor initializers can be fairly
complex expressions, not just constants.
My problem relates to constructors that return a value via a
reference parameter. How does one access these results? e.g.,
let's say I have these classes:
struct a { a(int &); };
struct b { b(int &); };
struct c { c(int &); };
Now I have this class:
struct X {
a cat;
b dog;
c mouse;
};
What I *want* to write is something like this:
X::X()
: cat(int aResult), dog(int bResult), mouse(int cResult)
{
switch(aResult) // ...
...
}
But this is illegal. Other options include having an int in the
class for each object, or haing a static int in the source file
for each object, but these seem less than elegant.
Suggestions?
Reid
--
Reid Ellis 264 Broadway Avenue, Toronto ON, M4P 1V9 Canada
rae@gpu.utcs.toronto.edu || rae%alias@csri.toronto.edu || +1 416 487 1383