Path: utzoo!utgpu!news-server.csri.toronto.edu!torsqnt!geac!alias!fred!rae From: rae@gpu.utcs.toronto.edu (Reid Ellis) Newsgroups: comp.lang.c++ Subject: constructor parameters Summary: How do you specify local variables for parameters to initilizer calls? Keywords: constructor, parameters, has-a Message-ID: Date: 1 Oct 90 19:33:47 GMT Sender: Reid Ellis Reply-To: Reid Ellis Organization: Alias Research, Inc. Toronto ON Canada Lines: 46 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