Hi folks,
I am writing an application in C, but I have the OOP functionality that C++ provides. (i.e., I can only use C library functions).
I have a function as follows in TSL1.cpp:
void TSL1_ExecuteTest (char *sCmdInt[])
/*******************************************************************************
Name: TSL1_ExecuteTest
Description: This function executes tests from current TSL1 board file.
Inputs: char *sCmdInt[] -- The command array
Outputs: None
********************************************************************************/
{
char returnData[256];
if ( sCmdInt[0] != NULL )
{
if ((pTSL1_Commands = new CTSL1_Commands) != NULL)
{
pTSL1_Commands->TSL1_InitialiseBoard();
if (strcmp(sCmdInt[0], "ReadMemory32") == 0)
pTSL1_Commands->TSL1_ReadMemory32(sCmdInt, returnData);
}
}
Now, in TSL1_Commands.cpp I have:
int CTSL1_Commands::TSL1_ReadMemory32 (char *sCmdInt[], char returnData[256])
/*******************************************************************************
Name: TSL1_ReadMemory32
Description: This function handles the call to read memory 32
Inputs: sCmdInt - A pointer to the command array
Outputs: returnData - The result from the command
********************************************************************************/
{
int iError = DIAG_ReadMem32(sCmdInt[1], returnData);
return iError;
}
In the function TSL1_ExecuteTest, a command will be passed to it and the relative function called. The problem is, there are ~200 different commands which may be passed to it. So, I am trying to create a look up table to hold all the command names, so that I don't have to create an if/else structure for all the different commands.
I have created a structure as follows:
typedef int (*myfunction)(char *[], char[]);
struct
{
myfunction thefunc;
const char* functionName;
}
lookUpTable[] = { {pTSL1_Commands->TSL1_ReadMemory32, "ReadMemory32"}, {NULL, NULL} };
For the moment, I have simply included it in the TSL1_ExecuteTest function. Errors are occurring as follows:
Compiling...
TSL1.cpp
C:\Projects\uMaster3xxxC++\IntelDriver\TSL1\TSL1.cpp(513) : error C2440: 'initializing' : cannot convert from '' to 'int (__cdecl *)(char *[],char [])'
None of the functions with this name in scope match the target type
C:\Projects\uMaster3xxxC++\IntelDriver\TSL1\TSL1.cpp(513) : error C2440: 'initializing' : cannot convert from 'char [13]' to 'int (__cdecl *)(char *[],char [])'
There is no context in which this conversion is possible
Error executing cl.exe.
TSL1.dll - 2 error(s), 0 warning(s)
Help?
1) Can anyone help with the errors/advise on better practice, or give me any other ideas as to what kind of structure to use?
2) If this struct is fine, where should I be declaring it (I know it probably shouldn't be in the middle of a function?)
Any help gladly received.