C++函数调用不起作用
C++ function calling does not work
在下面的代码中:返回值可能关闭,.主要问题是我得到一个错误,如果你需要确切的错误,它不会正确调用,只是评论说,我会在其他函数中也需要返回
int menu()
{
system("cls");
cout << "1 for gamemodes 2 for class editor (class editor not yet
made coming soon)" << endl;
system("pause>nul");
if (GetAsyncKeyState(VK_NUMPAD1))
{
gamemodes();
}
return 0;
}
int gamemodes()
{
system("cls");
cout << "pick a gamemode" << endl;
cout << "1 for team death match" << endl;
cout << "rest coming soon!!!!" << endl;
system("pause>nul");
if (GetAsyncKeyState(VK_NUMPAD1))
{
map_picker();
}
return 0;
}
int map_picker()
{
while (go = true)
{
system("cls");
cout << "pick a map" << endl;
cout << "1 for town" << endl;
system("pause>nul");
if (GetAsyncKeyState(VK_NUMPAD1))
{
town_load();
}
return 0;
}
int town_load()
{
return 0;
}
以下是需要修复的错误:
'gamemodes': identifier not found,
更新 对此代码的任何更新都将在此处引起来"如果我在 main 之前声明它们,它们会在被调用之前执行/使用
在 main
中使用它之前,您还没有声明gamemodes
。在 main
之前添加声明。
int gamemodes();
int main()
{
...
}
对OP评论的回应
宣言
int gamemodes();
不会导致函数调用。声明的存在是为了允许使用该函数。
该函数将在您拥有的代码块中main
调用:
if (GetAsyncKeyState(VK_NUMPAD1))
{
// This is where the function gets called.
gamemodes();
}
原始示例中有许多未声明的变量和函数。
当你在main function
之后声明一个函数,然后尝试在这个main function
中使用它时,你需要定义一个函数原型,该原型是声明为指定函数名称和类型签名的函数
因此,对于您的代码:
您需要先为函数GetAsyncKeyState
或原型添加代码,然后再为该函数添加代码。
与函数int gamemodes()
和map_picker()
相同
您还必须声明布尔变量和VK_NUMPAD1
变量go
您还必须添加主函数
这是一个没有编译错误的代码;但你必须为代码中使用的不同函数添加代码。
#include <iostream>
using namespace std;
int town_load();
int gamemodes();
int VK_NUMPAD1 = 1;
bool go = true;
int map_picker();
int GetAsyncKeyState(int VK_NUMPAD1) {
return 1;
}
int menu()
{
system("cls");
cout << "1 for gamemodes 2 for class editor (class editor not yet made coming soon)" << endl;
system("pause>nul");
if (GetAsyncKeyState(VK_NUMPAD1))
{
gamemodes();
}
return 0;
}
int gamemodes()
{
system("cls");
cout << "pick a gamemode" << endl;
cout << "1 for team death match" << endl;
cout << "rest coming soon!!!!" << endl;
system("pause>nul");
if (GetAsyncKeyState(VK_NUMPAD1))
{
map_picker();
}
return 0;
}
int map_picker()
{
while (go = true)
{
system("cls");
cout << "pick a map" << endl;
cout << "1 for town" << endl;
system("pause>nul");
if (GetAsyncKeyState(VK_NUMPAD1))
{
town_load();
}
return 0;
}
}
int town_load() {
return 0;
}
int main() {
return 0;
}
相关文章:
- C++为什么尽管我调用了void函数,它却不起作用
- C++函数调用不起作用
- 调用填充我的主体数组的函数不起作用
- 尝试调用成员函数指针不起作用
- 调用 setVisible(false) 在 QWidget 的构造函数中不起作用
- 可以't更改船舶位置,函数调用不起作用
- 为什么此模板函数调用在此函数中不起作用?
- 函数调用不起作用,矢量访问数据
- 调用函数从类返回私有变量不起作用
- 函数调用不起作用
- 析构函数体内的函数调用不起作用
- QStandardItemModel appendRow 在调用构造函数后不起作用
- C++ 为什么这些构造函数调用中有 3 个有效,但有一个不起作用?
- 使用默认构造函数调用的网格类不起作用 OpenGL C++
- 从Qt调用C++函数(插槽不起作用)
- boost库更新后,模板函数调用不起作用
- 为什么我的函数在调用时不起作用?
- 静态函数调用不起作用 (C++)
- 为什么 getline() 在 C++ 中不起作用?(调用'getline(std::ofstream&, std::string&)'没有匹配函数
- 函数在类中不起作用-函数调用缺少参数列表