
#include <glibmm/object.h>
#include <glibmm/init.h>

#include <iostream>

class Base : public Glib::Object {
public:
  Base() : Glib::Object() {
    std::cout <<  "RTTI offset in constructor: " << rtti_offset() << std::endl;
  }
  virtual ~Base() {}
  size_t rtti_offset(void);
protected:
  typedef int test_type;
};

size_t Base::rtti_offset(void) {
  Glib::ObjectBase* objectbase_ =
    Glib::ObjectBase::_get_current_wrapper((GObject*)gobj());
  Base* const obj = dynamic_cast<Base*>(objectbase_);

  // Uncomment this to get a crash !!!
  // std::cout << "Is the class derived ? " << obj->is_derived_() << std::endl;
  
  return (reinterpret_cast<size_t*>(obj) 
	  - reinterpret_cast<size_t*>(this))*sizeof(size_t);
}

class Derived : public Base {
public:
  Derived() : Base() {}
protected:
  test_type x;
}; 

int main(int argc, char	**argv)
{
  Glib::init(); 
  Derived w;
  std::cout <<  "RTTI offset in main: " << w.rtti_offset() << std::endl;
  
  return 0;
}

