This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: When C++ obeject is passed to C function
- From: Eljay Love-Jensen <eljay at adobe dot com>
- To: "VallabhaN" <VallabhaN at bristol dot com>, gcc-help at gcc dot gnu dot org
- Date: Tue, 06 Aug 2002 10:46:11 -0500
- Subject: 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