Mail Archives: djgpp/1998/02/25/05:00:34
DeHackEd <Not DOT given AT out> wrote:
: ok, here are the ammendments
: >I have a class witch looks somthing like this :
: >class Man {
: > int x,y,z;
: > ---------
: > void nextthink();
: void (*nextthink)();
: >}
: >
: >what I need is to be able to do somthing like :
: >nextthink() = run();
: nextthink = run;
: >
: >or
: >
: >nextthink() = attack();
This is C, not C++, but I had to write a command parser for my 'talker
system'. Here's what I did:
int run_command( player *p, char *command_name, char *str )
{
command *c;
for ( c = c_start; c; c = c->next )
{
if ( !strcasecmp( command_name, c->name ) )
{
if ( c->priv_required > p->residency )
return 0;
(c->function) ( p, str );
return 1;
}
}
return 0;
}
c->function is declared as void *function.
the (c->function) ( p, str ); is I think what you want. Am I correct, or
should I stop drinking beer again?
Matt
--
------------------------------------------------------------------------------
bLoOdRaGe, Coder of CiViL aNaRcHy. -=[telnet://Bird.ml.org 1998]=-
------------------------------------------------------------------------------
Politicians are the same over.
- Raw text -