Hi,
Have a look at this piece of code:
A aObj;
aObj = C();
aObj.foo();
aObj
is, even because you call
C();
and not
A();
, an instance of
A
. And in
A
, the method
foo
is empty. I did this test:
#include <iostream>
using namespace std;
class A;
class A {
public:
virtual void foo() { }
};
class C : public A {
public:
virtual void foo() { cout << "abc?" << endl; }
int i;
};
int main()
{
A aObj;
aObj = C();
aObj.i = 0;
aObj.foo();
}
I got a compiler error
'class A' has no member named 'i'
So, I'm sure
aObj
is an instance of
A
You can try
C aObj;
aObj = C();
aObj.foo();
instead of:
A aObj;
aObj = C();
aObj.foo();
Hope this helps.