Guest_imported
New member
- Jan 1, 1970
- 0
Hi,
Can someone tell me what I'm doing wrong in the following code? The code may appear somewhat useless and that would be almost true. The code is actually a simpler version of another set of more usefull code. By breaking down the original code, I had hoped to simplify the troubleshooting process. But I was unable to find a solution this way, I still get an error "Call of non function" (point of error is indicated in code) whenever I try to compile either sets of code. I appreciate any help offered, thanks in advance
//Header File
#ifndef functioncaller_h
#define functioncaller_h
class FunctionCaller
{
struct Tag
{
char* fname;
int (FunctionCaller::*fptr)(void);
};
Tag Tags[5];
int DoFunction1(void);
int DoFunction2(void);
int DoFunction3(void);
int DoFunction4(void);
public:
FunctionCaller(void);
int CallFunction(char* func);
};
#endif
//---------------------------------------------------------------------
//CPP file
#include <string.h>
#include <stdlib.h>
#include "functioncaller.h"
FunctionCaller::FunctionCaller(void)
{
//Define Tags
Tags[0].fname = "Function1";
Tags[0].fptr = &FunctionCaller:oFunction1;
Tags[1].fname = "Function2";
Tags[1].fptr = &FunctionCaller:oFunction2;
Tags[2].fname = "Function3";
Tags[2].fptr = &FunctionCaller:oFunction3;
Tags[3].fname = "Function4";
Tags[3].fptr = &FunctionCaller:oFunction4;
Tags[4].fname = NULL;
Tags[4].fptr = NULL;
}
int FunctionCaller::CallFunction(char* func)
{
//Match func with a Tag
for (int i = 0; Tags.fname != NULL; i++)
{
if ( strncmp(Tags.fname, func, strlen(Tags.fname) ) ==0)
return ( (Tags.fptr)() ); //"Call of non function" error occurs on this line
}
//Function name not found, so exit
exit(1);
}
Can someone tell me what I'm doing wrong in the following code? The code may appear somewhat useless and that would be almost true. The code is actually a simpler version of another set of more usefull code. By breaking down the original code, I had hoped to simplify the troubleshooting process. But I was unable to find a solution this way, I still get an error "Call of non function" (point of error is indicated in code) whenever I try to compile either sets of code. I appreciate any help offered, thanks in advance
//Header File
#ifndef functioncaller_h
#define functioncaller_h
class FunctionCaller
{
struct Tag
{
char* fname;
int (FunctionCaller::*fptr)(void);
};
Tag Tags[5];
int DoFunction1(void);
int DoFunction2(void);
int DoFunction3(void);
int DoFunction4(void);
public:
FunctionCaller(void);
int CallFunction(char* func);
};
#endif
//---------------------------------------------------------------------
//CPP file
#include <string.h>
#include <stdlib.h>
#include "functioncaller.h"
FunctionCaller::FunctionCaller(void)
{
//Define Tags
Tags[0].fname = "Function1";
Tags[0].fptr = &FunctionCaller:oFunction1;
Tags[1].fname = "Function2";
Tags[1].fptr = &FunctionCaller:oFunction2;
Tags[2].fname = "Function3";
Tags[2].fptr = &FunctionCaller:oFunction3;
Tags[3].fname = "Function4";
Tags[3].fptr = &FunctionCaller:oFunction4;
Tags[4].fname = NULL;
Tags[4].fptr = NULL;
}
int FunctionCaller::CallFunction(char* func)
{
//Match func with a Tag
for (int i = 0; Tags.fname != NULL; i++)
{
if ( strncmp(Tags.fname, func, strlen(Tags.fname) ) ==0)
return ( (Tags.fptr)() ); //"Call of non function" error occurs on this line
}
//Function name not found, so exit
exit(1);
}