- 论坛徽章:
- 0
|
下面的程序结构体一个个初化有错误,而用加注释的代替是正确的,搞了好久也没看出来,请帮我看看,thanks.
#include <iostream>;
#include <string>;
using namespace std;
static inline void do_open() {
std::cout << "do_open called\n";
}
static inline void do_close() {
std::cout << "do_close called\n";
}
static inline void do_save() {
std::cout << "do_save called\n";
}
static inline void do_quit() {
exit(0);
}
struct cmd_info {
char* cmd;
void (*funct)();
};
/*struct cmd_info cmd_list[]={
{"open", do_open},
{"close", do_close},
{"save", do_save},
{"quit", do_quit},
{NULL, NULL}
}; */
struct cmd_info cmd_list[5];
cmd_list[0].cmd="open";
cmd_list[0].funct=do_open;
cmd_list[1].cmd="close";
cmd_list[1].funct=do_close;
cmd_list[2].cmd="save";
cmd_list[2].funct=do_save;
cmd_list[3].cmd="quit";
cmd_list[3].funct=do_quit;
cmd_list[4].cmd=NULL;
cmd_list[4].funct=NULL;
static void do_cmd(const char *const cmd)
{
struct cmd_info *cur_cmd;
cur_cmd = cmd_list;
while ((strcmp(cur_cmd->;cmd, cmd) != 0) && cur_cmd != NULL)
{
cur_cmd++;
}
if (cur_cmd == NULL) {
std::cout << "Command not found\n";}
else {
cur_cmd->;funct();
}
}
void main()
{ char cmd[100];
while (1) {
std::cout << "Cmd: ";
std::cin.getline(cmd, sizeof(cmd));
do_cmd(cmd);
}
}
错误为:--------------------Configuration: c - Win32 Debug--------------------
Compiling...
c.cpp
E:\c.cpp(42) : error C2466: cannot allocate an array of constant size 0
E:\c.cpp(42) : error C2143: syntax error : missing ')' before '.'
E:\c.cpp(42) : error C2143: syntax error : missing ';' before '.'
E:\c.cpp(42) : error C2501: 'cmd_list' : missing storage-class or type specifiers
E:\c.cpp(42) : error C2371: 'cmd_list' : redefinition; different basic types
E:\c.cpp(41) : see declaration of 'cmd_list'
E:\c.cpp(42) : error C2143: syntax error : missing ';' before '.'
E:\c.cpp(42) : error C2059: syntax error : ')'
E:\c.cpp(43) : error C2466: cannot allocate an array of constant size 0
E:\c.cpp(43) : error C2143: syntax error : missing ';' before '.'
E:\c.cpp(43) : error C2501: 'cmd_list' : missing storage-class or type specifiers
E:\c.cpp(43) : error C2371: 'cmd_list' : redefinition; different basic types
E:\c.cpp(41) : see declaration of 'cmd_list'
E:\c.cpp(43) : error C2143: syntax error : missing ';' before '.'
E:\c.cpp(45) : error C2143: syntax error : missing ';' before '.'
E:\c.cpp(45) : error C2501: 'cmd_list' : missing storage-class or type specifiers
E:\c.cpp(45) : error C2369: 'cmd_list' : redefinition; different subscripts
E:\c.cpp(41) : see declaration of 'cmd_list'
E:\c.cpp(45) : error C2143: syntax error : missing ';' before '.'
E:\c.cpp(46) : error C2143: syntax error : missing ';' before '.'
E:\c.cpp(46) : error C2501: 'cmd_list' : missing storage-class or type specifiers
E:\c.cpp(46) : error C2369: 'cmd_list' : redefinition; different subscripts
E:\c.cpp(41) : see declaration of 'cmd_list'
E:\c.cpp(46) : error C2143: syntax error : missing ';' before '.'
E:\c.cpp(4 : error C2143: syntax error : missing ';' before '.'
E:\c.cpp(4 : error C2501: 'cmd_list' : missing storage-class or type specifiers
E:\c.cpp(4 : error C2369: 'cmd_list' : redefinition; different subscripts
E:\c.cpp(41) : see declaration of 'cmd_list'
E:\c.cpp(4 : error C2143: syntax error : missing ';' before '.'
E:\c.cpp(49) : error C2143: syntax error : missing ';' before '.'
E:\c.cpp(49) : error C2501: 'cmd_list' : missing storage-class or type specifiers
E:\c.cpp(49) : error C2369: 'cmd_list' : redefinition; different subscripts
E:\c.cpp(41) : see declaration of 'cmd_list'
E:\c.cpp(49) : error C2143: syntax error : missing ';' before '.'
E:\c.cpp(51) : error C2143: syntax error : missing ';' before '.'
E:\c.cpp(51) : error C2501: 'cmd_list' : missing storage-class or type specifiers
E:\c.cpp(51) : error C2369: 'cmd_list' : redefinition; different subscripts
E:\c.cpp(41) : see declaration of 'cmd_list'
E:\c.cpp(51) : error C2143: syntax error : missing ';' before '.'
E:\c.cpp(52) : error C2143: syntax error : missing ';' before '.'
E:\c.cpp(52) : error C2501: 'cmd_list' : missing storage-class or type specifiers
E:\c.cpp(52) : error C2369: 'cmd_list' : redefinition; different subscripts
E:\c.cpp(41) : see declaration of 'cmd_list'
E:\c.cpp(52) : error C2143: syntax error : missing ';' before '.'
E:\c.cpp(54) : error C2143: syntax error : missing ';' before '.'
E:\c.cpp(54) : error C2501: 'cmd_list' : missing storage-class or type specifiers
E:\c.cpp(54) : error C2369: 'cmd_list' : redefinition; different subscripts
E:\c.cpp(41) : see declaration of 'cmd_list'
E:\c.cpp(54) : error C2143: syntax error : missing ';' before '.'
E:\c.cpp(55) : error C2143: syntax error : missing ';' before '.'
E:\c.cpp(55) : error C2501: 'cmd_list' : missing storage-class or type specifiers
E:\c.cpp(55) : error C2369: 'cmd_list' : redefinition; different subscripts
E:\c.cpp(41) : see declaration of 'cmd_list'
E:\c.cpp(55) : error C2143: syntax error : missing ';' before '.'
Error executing cl.exe.
c.exe - 44 error(s), 0 warning(s)
在BC中编译错误提示为:cmd_list[0].cmd="open";两次赋值。 |
|