Declaration of virtual function.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

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


Date: Wed, 01 Sep 2004 21:13:57 +0200


I have a problem with the declaration of virtual function. What do I do
wrong? Why the compiler 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

  • Problem with declaration of virtual function
    ... I have a problem with the declaration of virtual function. ... Why the compiler says nothing? ... Pierre Couderc ...
    (comp.lang.cpp)
  • Re: Question about 6.2.4 of C99
    ... compilers to reuse memory in some cases, ... muddying up the semantics and/or making the programmer work harder. ... than it would be if the declaration created and really ... I understand why the VLA rules are the way they are. ...
    (comp.std.c)
  • Re: Question about 6.2.4 of C99
    ... compilers to reuse memory in some cases, ... muddying up the semantics and/or making the programmer work harder. ... the same way it does for VLAs? ... I write an intra-block declaration and every time I read one I ...
    (comp.std.c)
  • Re: C-AUX / C and binary portability
    ... trigraphs, digraphs, and K&R declarations are, in many C compilers, currently at the level where they will cause compiler warnings. ... which is ambiguous, but in this case, it will just assume that the declaration was intended. ... the reason is that, if one does infact include headers and expand macros here, then the generated code will depend on whatever macros/constants/... ...
    (comp.lang.misc)
  • 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)