7f6 Subj : class member initialisation To : borland.public.cpp.borlandcpp From : David Currie Date : Fri Oct 17 2003 12:56 am Consider the following generalisation class Apple { private: int i1; // data members int i2; public: Apple(int ii1,int ii2); // Constructor // Destructors + methods etc } class FruitBox { private: char c1; Apple a1; FruitBox (say) (char c); // Constructor 1 FruitBox(char c) : a1(value1,value2); // Constructor 2 // example FruitBox(something s) // Constructor 3 // example // Destructors + methods etc } FruitBox::FruitBox(char c) // Constructor 1 { /* ... make a decision (perhaps based on char c) how to construct Apple a1 */ Now how do i construct Apple a1 here ? } ps : I know using constructor 2 the compiler can construct Apple for me but in general i dont know how to construct Apple until i am already in the function 1) Apple a1 exists (its a part of the FruitBox object) can i construct Apple a1 here, if so how i know i can redesign methods here (say default Apple constructor + setters) or say Apple localApple(value1,value2); (this->)a1 = localApple; requiring operator= (assignment operator + copy methods etc) and to a degree this is duplicating effort. but in general this is not desired (for many reasons ...) how do i initialise it directly ? is it initialisable by reference ? this->a1(value1,value2) ? can a correct syntax construct Apple here ? if so what is it 3) For that matter, consider constructor 3 can constructor 3 (after some code sequence ...) construct itself using constructor 1 ? if so what is the appropriate syntax for one constructor to call another constructor? 4) Is all this a design limitation of C++? any responses would be greatly appreciated. } . 0