Hello, I am doing a program that requires me to use the base constructor of a class when instantiating the derived class and just cannot get a hold on this. Please refer to the code below:
Base Class:
Nothing too fancy. I need to create an object with the CustomerData class that uses the constructor from PearsonData that takes the 7 arguements. Is there anyway this can be done?
class SuperClass
{
public:
SuperClass(int foo)
{
// do something with foo
}
};
class SubClass : public SuperClass
{
public:
SubClass(int foo, int bar)
: SuperClass(foo) // Call the superclass constructor in the subclass' initialization list.
{
// do something with bar
}
};
Thanks a lot. I've seen this but I still don't quite understand how to implement it in my program. The description asks to put the constructor definitions in the cpp files and the headers in the .h files.
I've tried different combinations of the above and none of it seems to work. Any suggestions?
The derived constructor needs to have enough arguments to call the parent constructor plus enough arguments to handle its own constructor.
In your case: