我正在嘗試編譯以下代碼,但收到此錯誤:
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 }
我很感激這讓我發瘋的幫助。
uj5u.com熱心網友回復:
如果該函式validate不是靜態成員函式,那么您需要指定一個呼叫它的物件,例如
if (game->validate(game->currentCommand())) {
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/450458.html
上一篇:OSError:[Errno8]Execformaterror:'/home/ec2-user/Desktop/chromedriver'在AWSEC2ARM風味機器中使用Chro
下一篇:python中的類屬性和函式遞回
