CFanatic

Go Back   CFanatic > Programming > C++ Programming

Join CFanatic Forum Now

Reg Fucntion Pointers topic posted under C++ Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 06-27-2007, 10:27 AM
Junior Member
 
Join Date: Jun 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
sowmi is on a distinguished road
| More
Reg Fucntion Pointers

Hi All,

I am trying to implement the concept of function pointer in C++.
While compiling i got some errors which I couldnt figure out the reason .
So,Please let me know what changes should be done for resolving that error.

I am trying to execute one particular command function when the commandis pressed.Likewise, I have 100 commands and whenever the commands are pressed the corresponding function + arguements should be passed and the function pointer should execute the command.


Below are my code,

Code:
command.h
**********
#define FUNCPTR  void *
#define MAX_NUM_COMMANDS 3

typedef struct
{
   char command[LINELEN];                           /* name of the command */
   char parm1[LINELEN];                             /*parameter 1 */
   char parm2[LINELEN];                             /*parameter 2 */
                                      
} ExeCmd_s;
class FunctionEntry
{

public:
    char* commandString;
    FUNCPTR pFun;   
    int SearchCommand(char* command);
};
FunctionEntry funArr[MAX_NUM_COMMANDS]=
{
	    {"aaa",(FUNCPTR)aaa},
            {"bbb", (FUNCPTR)bbb},
   	    {"ccc",(FUNCPTR)ccc}

};
enum commandName
{
	aaa = 0,
	bbb
};


command.c
**********
void void Execute ()
{
  .........
  .........
 Execmd execmd;
 FunctionEntry command;
 int rc;
 if(0 != SearchCommand(exeCmd.command))
 {
    command = FunctionEntry.SearchCommand(exeCmd.command);
    switch((int)command.numOfArguements)
    {
         case Zero :
           rc = ((command.pFun)();
           break;
	 case one:
	   rc = ((command.pFun),exeCmd.parm1);
	   break;
    }
 }
 else
 {
   printf("No match");
 }

}



//Function to search and returns the index of the command

int FunctionEntry :: SearchCommand(char* command)
{
     
     ExeCmd_s exeCmd;  //already had a Structure where I am extracting the commandname..
     int index = 0;     
     while(index < MAX_NUM_COMMANDS)
     {
	 if(strcmp(exeCmd.command,funArr[index]) == 0)
	 {
	    return &funArr[index];
	 }
         index++;	
    }
     return NULL;
}




Please let me know where i should change the code.
Expecting some solutions for this code ASAP .

Thanks,
Sowmi

Last edited by shabbir; 06-27-2007 at 11:30 AM. Reason: Code block
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Virtual Functions and pointers Spogliani C++ Programming 1 07-15-2008 01:58 AM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 02:10 AM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board