我正在尝试编译以下代码,但收到此错误:
CommandProcessing.cpp:86:58: error: cannot call member function âbool CommandProcessor::validate(std::string)â without object
86 | if (CommandProcessor::validate(game->currentCommand())) {
以下是相关代码。我不明白为什么它不会编译,因为我确实提供了一个非常特定的成员对象。我觉得我应该补充一点,consolePlay是一个全局/独立的功能。
bool consolePlay(CommandProcessor* game) {
83 cout << "game state: " << game->currentCommand();
84 game->getCommand();
85
86 if (CommandProcessor::validate(game->currentCommand())) {
87 if (game->currentCommand() == "loadmap") {
88 game->setState("maploaded");
89 return true;
120 int main(int argc, char *argv[]) {
121
122 if (argc == 0) {
123 cout << "You must specify console or file input in command line" << endl;
124 exit(0);
125 }
126
127 if (argc > 1 && (argv[0] != "-console" || argv[0] != "-file")) {
128 cout << "Invalid command line argument(s)" << endl;
129 exit(0);
130 }
131 CommandProcessor *game = new CommandProcessor();
132 if (argv[argc-1] == "console")
133 while (consolePlay(game)) {
134 continue;
135 }
currentCommand访问指向Command类不同成员的指针数组中的成员,该数组本身是CommandProcessing的成员变量。
22 string CommandProcessor::currentCommand() {
23 Command temp = *commandList[commandCount];
24 return temp.command;
25 }
我很感激你的帮助这让我抓狂。