Hi I'm a newbie and I search the forum for a post on using a structure. and I am sorry if I missed a post about this.I have read up on structures and I did not see anything like this code. I kind of understand them and I try to understand other codes to help me to understand and to become a better programmer. I came across this code and I loaded it up in C++ to see how it works, but I get errors. I try to figure it out but like I said I am new at this and was hoping someone out there could explain this or a better way to write it.
In the header file it has the following code.
Code:
typedef struct {
char* cmd;
void(*funcptr)(char *arg);
} cmdStruct_t;
void link_cmd(void);
void parse(char *cmd);
void cmd_reset(char *arg);
void cmd_help(char *arg);
void cmd_info(char *arg);
Then on the main code block it has the following code.
Code:
cmdStruct_t CMD_LIST[] = {
{"reset",cmd_reset},
{"help",cmd_help},
{"info",cmd_info},
};
When I compile the program I get the following errors.
error LNK2001: unresolved external symbol "void __cdecl cmd_info(char *)" (?cmd_info@@YAXPAD@Z)
1>new2.obj : error LNK2001: unresolved external symbol "void __cdecl cmd_help(char *)" (?cmd_help@@YAXPAD@Z)
1>new2.obj : error LNK2001: unresolved external symbol "void __cdecl cmd_reset(char *)" (?cmd_reset@@YAXPAD@Z).
it looks to me like they are predefining the structure with a variable. I am trying to figure it out on how it works. could someone please explain. I thought this would be a better way instead of using arrays predefined. Not sure which would be better.
Thanks
Dorato