chpicker
Programmer
- Apr 10, 2001
- 1,316
Is there a way to overload a class constructor but still be able to reuse code? For instance, say I have two constructors for MyClass:
[tt]
MyClass::MyClass();
MyClass::MyClass(int a);
[tt]
I would like the second constructor to call the default constructor. If passed a parameter, it will do all of the same things the normal constructor does plus more code that is specific to the parameter.
Is there a way to do this, or am I stuck duplicating the code in both constructors?
Ian
[tt]
MyClass::MyClass();
MyClass::MyClass(int a);
[tt]
I would like the second constructor to call the default constructor. If passed a parameter, it will do all of the same things the normal constructor does plus more code that is specific to the parameter.
Is there a way to do this, or am I stuck duplicating the code in both constructors?
Ian