
pointers to functions in structs which take a pointer to that struct as an arg
Gurus,
I can't find documentation on this anywhere, though I may be missing
something obvious since I am home-schooled in this sort of C stuff.
I want to create a struct in C which (in lean form) looks like this:
typedef struct {
int x,y,h,w;
void (*paint)(lwin*),
(*born) (lwin*),
(*die) (lwin*);
int (*keypressed )(lwin*,int,int),
(*clicked )(lwin*,int,int,int);
Quote:
} lwin;
(That is, I want to pass a pointer to the structure when I call the
functions by the function pointers, like with c++'s 'this')
When I compile in gcc I get errors like,
test.c:4: parse error after '*'
for each time I try to declare an argument as type (lwin *).
I thought declaring 'struct lwin;' before doing the typedef would fix
it -- it doesn't, nor does using the alternate (c++?) syntax "struct lwin
{.....};".
I know what I want to do can be achieved in C++ using member
functions, but I don't want to use C++.
My question is: Can I do this? What is the proper syntax?
I would appreciate an e-mail cc to twm(a)cmu.edu.
Thank-you!
Tom 7