vtable offset 0

What exactly does this mean?
function=&virtual table offset 0

(The function is a static member function pointer)

This is a message from gdb. I'm trying to figure out what's going wrong in my code. Keep getting SIGSEGV.
have you actually defined the function that this pointer will be pointing to??
Yes they are defined as virtual functions.
This is where I say 'show the code'
It goes something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Dummy { };
class EventManager { //Singleton
     private:
          static void (EventManager::*someFunc)(void); // This of course is initialized to be 0
          /.../
          static void someEvent(void) { // This HAS to be static!
              EventManager &em = instance() // Singleton!
              (em.*someFunc)(); // SIGSEGV
          }
     public: 
          void setFunction(void (Dummy::*function)()) {
               /.../
               someFunc = reinterpret_cast<void (EventManager::*)(void)>(function);
          }
}

class Main : public EventManager {
    /.../
         Main : EventManager() { setFunction(void (Dummy::*)()>(&Main::function)) }
    protected:
         virtual void function(void) { }
    /.../
};


Now the final user should be able to implement this as

1
2
3
4
5
6
class MyMain : Main {
     /.../
     protected:
          virtual void function() { //put sth in here }
     /.../
}


Thank you for the fast answers so far ;-)
Is this safe casting??
I'm going off to re-check the blurb on reinterpret_cast - but this doesn't look right to me.

I think it goes like this:

pointer to class member functions are not actually address, like normal pointers, they are actually
indexes.
So line 19 when you do this:
Main : EventManager() { setFunction(void (Dummy::*)()>(&Main::function)) } you are getting the index of Main::function which is a virtual function
This is passed to Line 11:
1
2
3
4
          void setFunction(void (Dummy::*function)()) {
               /.../
               someFunc = reinterpret_cast<void (EventManager::*)(void)>(function);
          }

But Event Manager has no virtual members - so the index into the virtual function table is invalid.

Well something like that anyway I think :-)
Last edited on
Thank you!! I still get the SIGSEGV but at least the vtable problem seems to be fixed...
You cannot call a member function without specifying which object the member function belongs to.

Read up on this. This should clarify you on your problem.
http://www.parashift.com/c++-faq-lite/pointers-to-members.html
Thanks a lot :-)
Topic archived. No new replies allowed.