Original Post
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: 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: 123 560 where 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 like myClass(const int& X, const int& Y) : myClass() work?
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;
}