Tech Support > Microsoft Windows > Development Resources > Problem with virtual function
Problem with virtual function
Posted by Pierre Couderc on September 2nd, 2004



I have a problem with the declaration of virtual function. What do I do
wrong? Why the compiler says nothing? (MS VC++ 6)

It is very simple (see my comment below):

class A
{
public :
A(){;}
};

class B : public A
{
public :
B() : A() {;}
virtual void bad() {;}
};

class C : public B
{
public :
C() : B() {;}
void bad() {;}
};


BOOL CVirtuApp::InitInstance()
{
A* many[2];
C* p = new C;
ASSERT(_CrtIsValidHeapPointer(p));
many[0] = p;
ASSERT(_CrtIsValidHeapPointer(many[0])); // FAILS here
ASSERT(many[0]== p); // OK;
....
}

When the ASSERT fails, I see that the paramter of CrtIsValidHeapPointer
is XXXX at first call and XXXX+4 at second call.


So what am I doing wrong?

Thank you in advance
Pierre Couderc

Posted by Andrey Romanenko on September 2nd, 2004


Pierre Couderc wrote:
Hi there,

seem everything is correct. The class A have NO pointer to virtual
functions table, but class C have one because of virtual function "bad".

Andrey



Similar Posts