Featured post
c++ - Derived class vtable corrupted? -
need in root causing vtable corruption issue(not sure if that’s happening). here simplified version of code.
class cbase { public: cbase() virtual ~cbase() virtual void base_virtual_fn1() = 0; virtual void base_virtual_fn2(); private: cdata _data; }; class cderived : public cbase { public: cderived(); virtual ~cderived() virtual void base_virtual_fn1(); virtual void base_virtual_fn2(); virtual void derived_virtual_fn1(); virtual void derived_virtual_fn2(); private: // contains vectors , maps, integers, bools. };
when create instance of cderived , call derived class virtual function derived_virtual_fn2 other function gets called i.e. derived_virtual_fn1.
calls base_virtual_fnx has no issues.
this happens object created on heap , not local object.
these classes in shared library. i’m using gcc 3.4.2 on linux (sles 10). there no pragma pack directive in of code , there mix of c , c++ code (extern c used). issue here?
i forgot mention there there tons of other code (executable, libraries)
here nasty mistake made took me forever find. compiler/debugger/valgrind gave me no insight going on. there should someway debug these kinds of errors:
the base class compiled in library "some_package" defined:
class interface { virtual int function1(int); #ifdef some_package virtual int function2(int); #endif virtual int function3(int); } class base : public interface { int function1(int); int function2(int); int function3(int); }
the derived class compiled later without some_package defined
class derived : public base { int function1(int); int function3(int); }
calls function3 caused jumps function2 able figure out debugger, took me long time find cause.
- Get link
- X
- Other Apps
Comments
Post a Comment