Toondalis wrote:
Hi,
newbie question
How can i mix C and C++. and get compile
How could i add memeber function in C
Best you can do is declare a function pointer within your structure and
then later initialise it to point to the function. Your function should
also take a pointer to the structure so it can access the other data. e.g.
#include "stdio.h"
typedef void (*FP_VOID)(); /* ptr to function returning void */
typedef struct {
int bPlay;
FP_VOID pPlay; /* function pointer */
} ANIMATION;
void Play(ANIMATION *this, int a) {
printf("bPlay=%d\n",this->bPlay);
printf("a=%d\n",a);
}
int main(void) {
ANIMATION anim = { 7, Play };
anim.pPlay(&anim,10);
return 0;
}
Of course, if this is what you need, you may want to reconsider just
using C++. Note that doing the above loses the compilers argument
type-checking ability for "Play".
Regards,
Ed.