   I should know this
  But alas, I don't.I'd like to write my C++ constructors such that the only difference between the default constructor and one with parameters is only the changes made by the parameters. Thereby easing maintainance by requiring that I only modify the default constructor, and the changes will trickle down.For example:class myClass{public:myClass();myClass(const int& X, const int& Y);private:int x, y, z;}myClass::myClass(){x = 1;y = 2;z = 3;}myClass::myClass(const int& X, const int& Y){x = X;y = Y;}With this class the way it is now, if I were to do this:myClass thing1();myClass thing2(5, 6);cout << thing1 << endl << thing2 << endl;the output would be:123560where that 0 could be just about anything, and it probably would not be 3.Now I know I could just use default values to set x, y, and z if they were not supplied, but that only works in simple cases such as this. If I wanted a function to be called in the default constructor, for example, and wanted that same function called in the other constructor, I'd have to type it twice. Not that this is the worst thing in the world, but it would be very nice if I did not have to. Is there a way to make something likemyClass(const int& X, const int& Y) : myClass()work?   
Nope.;  /cryThanks, Sneftel.   ;Quote:Original post by CyberSlag5kIs there a way to make something likemyClass(const int& X, const int& Y) : myClass()work?myClass( const int & X , const int & Y ) { common_init(); }myClass( const int & X , const int & Y ) : myClassBase() {}Overkill for this situation, but useful in more complex ones.   ;  Having an initialization function is an excellent way to emulate the behavior I want. It makes construction a bit heftier, but if I've done my job I'll have minimized the number of objects being created anyway. What's silly is that I do that for my destructors to avoid redundant clean-up code. It should have occurred to me to do the same. But I am a silly silly man. Thanks, MaulingMonkey!What's up with the second line, though? Is that meant to be the class's declaration, calling its base's constructor as well?   ;Quote:Original post by CyberSlag5kHaving an initialization function is an excellent way to emulate the behavior I want. It makes construction a bit heftier, but if I've done my job I'll have minimized the number of objects being created anyway. What's silly is that I do that for my destructors to avoid redundant clean-up code. It should have occurred to me to do the same. But I am a silly silly man. Thanks, MaulingMonkey!What's up with the second line, though? Is that meant to be the class's declaration, calling its base's constructor as well?Yes.  In this case, you actually don't need it since the default will be called anyways :-).  More useful for situations where certain members /require/ non-default construction, but the same one.   