This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: When C++ obeject is passed to C function


Hi Vallabha,

Don't try to put instance method virtual function pointers into a C structure of function pointers. An instance method virtual function pointer is a different animal.

You should use glue/stub routines.

class Base {
public:
// Option #1 entry stub...
static void KickEntry(void* self) {
Base* base = static_cast<Base*>(self);
base->KickSelf();
}
// ...end-of-#1.

// Option #2 entry stub...
/*final*/ void Kick() { KickSelf(); }
// ... end-of-#2.

virtual void KickSelf() = 0;
};

Put KickEntry() or Kick() into your C structure of function pointers. KickSelf() won't work.

My preference is KickEntry(), but if you are careful Kick() will work too.

Also, strongly consider making KickSelf() private. Or at least, protected.

--Eljay


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]