I am making a class which inherits off another and must return the value of a function in the base class… It is confusing so I will let the code speak for itself…
class ParentClass {
public:
virtual bool getMyVal();
};
bool ParentClass::getMyVal() {
return true; // in my program there is a bit more to it
}
class ChildClass : public ParentClass {
public:
bool getMyVal();
};
bool ChildClass::getMyVal() {
CalculateMassOfSun();
return parent::getMyVal(); // Please make sure you read below...
}
So this is just an example of what I want to do, not the actual code. As you can see, in ChildClass::getMyVal(), is basically needs to do some pre-computation then run the same function in the parent class and return its value. I know that it is a virtual function in the parent, and that I have not gone about invoking the function in the parent the right way – it is how it is done in PHP and the only way I can think of that makes sense to me and hopefully others at the moment.
So how would I go about doing this? At the moment, I have found something along the lines of:
bool ChildClass::getMyVal() : /*ParentClass::*/getMyVal() { ... }
however it does not return the value here.
Thanks in advance for your responses.
To invoke the base definition of
getMyValjust prefix the call with the base type name