Path: utzoo!attcan!uunet!yale!cmcl2!rna!kc From: kc@rna.UUCP (Kaare Christian) Newsgroups: comp.lang.c++ Subject: constructor calls constructor? Keywords: constructors, this Message-ID: <601@rna.UUCP> Date: 26 May 89 14:02:38 GMT Organization: Rockefeller University - Neurobiology Lines: 36 A question, if you please. I have a class that has several constructors. class X { ... public: X(); X(int n); All of these constructors have some mundane chores that must be accomplished, plus there are extra chores for those that take extra arguments. What I tried to do was have the "parameter taking" constructors all call the parameterless constructor. So, I had something like X::X(int n) { X(); // the extra work } This didn't work, the call to X() created a new object, it didn't initialize the current object. (I guess this makes sense, 'cause a statement like A=X() should create a new object.) Then I tried X::X(int n) { this->X(); // the extra work here } But this didn't pass muster, Zortech C++ complained that "X wasn't a member of class X." Is there a way for one constructor to call another, simply to have some chores performed, while avoiding real construction? (I know I can have all the constructors call some helper function, but that seems too roundabout.) Thanks, Kaare Christian