Skip navigation

I made that mistake and my _vfptr was always 0 in the debugger!

It turns out that if you have:

class Object : public SomeInterfaceThatHasVirtualMemberFunctions
  int member1 ;
  float member2 ; 

    // !! NEVER, EVER DO THIS!!  EVER!
    memset( this, 0, sizeof( Object ) )

WHat happens is the v_table apparently gets 0’d out as well, not just the members.


One Comment

  1. cppcheck static analyzer will warn you if you do that.


    $ cat test.cpp
    class foo {
      virtual ~foo() {}
      memset(this, 0, sizeof(foo));
    $ cppcheck -v -s -a -f -j 2 test.cpp
    Checking test.cpp...
    [test.cpp:8]: (error) Using 'memset' on class

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: