www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/25/05:00:34

From: Matthew Busigin <matt AT xwing DOT xwing DOT org>
Newsgroups: comp.lang.c++,comp.os.msdos.djgpp,rec.games.programmer
Subject: Re: pointer to function ??
Date: 25 Feb 1998 00:43:52 GMT
Organization: XWING Private Internet Site
Lines: 52
Message-ID: <eowsp4.f8@xwing.xwing.org>
References: <6c7ltq$ms1$1 AT o DOT online DOT no> <uHdsj8tP9GA DOT 229 AT upnetnews03>
NNTP-Posting-Host: 207.245.212.35
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019