When C++ obeject is passed to C function
Eljay Love-Jensen
eljay@adobe.com
Tue Aug 6 08:46:00 GMT 2002
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
More information about the Gcc-help
mailing list