Hi all,
I have an issue with a piece of code that I am writing. The problem I'm facing is that I have a base class and a derived class, and the base class contains a pure virtual function. I then want to overload the pure virtual function with a non-virtual function in the base class, with the implementation of the non-virtual function including a call to the pure virtual function. When I try to run this, the compiler seems to overwrite the overloaded function with the implementation of the pure virtual function in the derived class, and hence cannot execute the call to the non-virtual function.
I have googled this issue, and come across it on a few websites, but I don't totally understand the explanations given, nor the appropriate solution for what I want to do. Most websites I've looked at that address this issue point to the following webpage as reference: http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.6.
I'm not quite sure what the explanation there means for what I want to do though, and it doesn't cover the issue of inheritance along with virtual function overloading.
I've included a bit of example code to explain the problem I want to solve:
class BaseClass
{
public:
void setInputParameter()
{
inputParameter_ = inputParameter;
}
void computeFunction( const double& inputParameter )
{
setInputParameter( inputParameter );
this->computeFunction();
}
protected:
virtual void computeFunction() =0;
private:
inputParameter_;
}
class DerivedClass : public BaseClass
{
public:
void computeFunction()
{
fooVariable_ = 20.0;
}
protected:
private:
double fooVariable_;
}
I hope someone can help me sort this out.
Thanks in advance,
Cheers,
Kartik