Hi,
I have a problem calling a function that is virtual in abstract and implemented in child:
class ClassA
{
public:
virtual int sum() = 0;
};
The child class:
header:
class ClassB : public ClassA
{
public:
ClassB(int startValue);virtual int sum();
private:
int fStartValue;
};
source:
ClassB::ClassB(int startValue) :
fStartValue(startValue)
{
}int ClassB::sum()
{
int sum = fStartValue;
for (int i = 0; i < 4; ++i)
{
sum += i;
}
return sum;
}
The compilation goes without warnings nor errors, but when debugging I get an exception when calling sum():
main src:
ClassA* pObjectA;
ClassB objectB(10);int main()
{pObjectA = &objectB;
total += pObjectA->sum();
}
What can be the reason for that?
How can I solve this?
Hello,
this question is already solved in the thread below:
https://community.nxp.com/thread/453904
Regards,
Martin