Problem with declaration of virtual function

From: Pierre Couderc (pierre_at_couderc.ccNOSPAM)
Date: 09/02/04


Date: Thu, 02 Sep 2004 07:22:55 +0200


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

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



Relevant Pages

  • Declaration of virtual function.
    ... I have a problem with the declaration of virtual function. ... Why the compiler says nothing? ... Pierre Couderc ...
    (microsoft.public.vc.mfc)
  • Re: Question about multiple files
    ... No. extern just means: The actual definition is somewhere else. ... the compiler can differentiate between declaration and definition just ... > declaration it finds and in this way can I write code expecting it to be ... When the compiler reaches the line foo(); ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Interview questions
    ... How did your compiler know where to get the entry point for Hello? ... > without calling a wrapper function. ... *without* any public definition of the virtual function table. ... The programmer is playing the role of the compiler. ...
    (comp.lang.cpp)
  • Re: Question about multiple files
    ... but say I declare with extern. ... > the compiler can differentiate between declaration and definition just ... >> declaration it finds and in this way can I write code expecting it to be ... > When the compiler reaches the line foo(); ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Cpp Considered Harmful
    ... >> programming language, the compiler, the IDE, the libraries, etc. ... source file, the implementation shall locate the declaration, (and ... to name one of the defining source files on the command line that initiates ... The counterpart to this in Java is accomplished using the following: ...
    (comp.lang.cpp)