hi all,
I have a parent and child class. The constructor for the parent class accepts three arguments and would correctly initialise an instance of the child class.
Is it possible to arrange it so that when an instance of the child class is created, it is constructed with its parent class constructor?
At the moment, I call the parent class constructor explicitly from the child class constructor and define a argument-less protected constructor in the parent class, which it seems the compiler (VC8) also automatically calls at the end of the child constructor. This works, but it strikes me as a little hack-ish and i'm interested to know if there is a better way of doing this.
An example:
Code:
class ParentClass
{
public:
ParentClass(int arg1, int arg2, int arg3);
protected:
ParentClass(){}
//etc
};
class ChildClass : public ParentClass
{
public:
ChildClass(int arg1, int arg2, int arg3) {::ParentClass(arg1, arg2, arg3); //compiler inserts a call to ::ParentClass() also}
//etc
};
thanks,