MPC5748G C++ inheritance

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MPC5748G C++ inheritance

582 Views
kfirbs
Contributor III

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?

0 Kudos
Reply
1 Reply

489 Views
martin_kovar
NXP Employee
NXP Employee

Hello,

this question is already solved in the thread below:

https://community.nxp.com/thread/453904 

Regards,

Martin

0 Kudos
Reply