错误"菜单"未在此范围内声明C++
error 'menu' was not declarated in this scope C++
下面是代码
#include <iostream>
#include <cstdlib>
#include <math.h>
using namespace std;
int x,d,p,r,se,me;
int y,s,c,op;
void calculator1()
{
{
start2:;
system("color 0A") ;
cout << "Primul Nr. " ; cin >> x ;
cout << "Nr Doi. "; cin >> y ;
start1:;
system("color 0A");
cout << "n 1. Suma";
cout << "n 2. Diferenta";
cout << "n 3. Produsul";
cout << "n 4. Catul (Fara REST)";
cout << "n 5. Catul (Cu REST)";
cout << "n Ce operatie ? ";cin >> op ;
s = x + y;
d = x - y;
p = x * y;
c = x / y;
r = x % y;
if(op == 1)
{
cout << "n Suma n" << s ;
system("pause");
cout << "1. Inapoi la calulator" <<endl;
cout << "2. Inapoi la meniul principal";
cin >> me;
if(me==1){
goto start2;
}
if(me==2){
system("cls");
}
}
else if(op == 2)
{
cout << "n Dif. n" << d ;
system("pause");
cout << "1. Inapoi la calulator" <<endl;
cout << "2. Inapoi la meniul principal";
cin >> me;
if(me==1){
goto start2;
}
if(me==2){
system("cls");
}
}
else if(op == 3)
{
cout << "n Prod n" << p ;
system("pause");
cout << "1. Inapoi la calulator" <<endl;
cout << "2. Inapoi la meniul principal";
cin >> me;
if(me==1){
goto start2;
}
if(me==2){
system("cls");
}
}
else if(op == 4)
{
cout << "n Cat. n" << c ;
system("pause");
cout << "1. Inapoi la calulator" <<endl;
cout << "2. Inapoi la meniul principal";
cin >> me;
if(me==1){
goto start2;
}
if(me==2){
system("cls");
}
}
else if(op == 5)
{
cout << "n Cat. " << c << " rest " << r << "n ";
system("pause");
cout << "1. Inapoi la calulator" <<endl;
cout << "2. Inapoi la meniul principal";
cin >> me;
if(me==1){
system("cls");
goto start2;
}
if(me==2){
system("cls");
menu();
}
}
else
{
system("color cf");
cout << "n Alegere Gresita n" ;
system("pause");
system("CLS");
goto start1;
}
}
和延续
}
void menu()
{
system("color 0A");
cout << "1. Calculator (Simplu)n";
cout << "nAlege. ";
cin >> se ;
if(se==1)
{
system("cls");
calculator1();
}
}
int main()
{
menu();
}
完整代码和编译器错误:
"error: 'menu'未在此范围内声明"
我使用的是Windows 7 Ultimate和编译器GNU GCC compiler
请帮帮我!
谢谢
在函数calculator1
的主体内使用函数menu
。但是函数menu
是在函数calculator1
定义之后声明的。所以编译器知道calculator1
menu
是什么意思为了避免错误,可以在函数calculator1
之前声明函数menu
,然后在函数calculator1
之后定义它
函数递归地调用自己也是一个坏主意。尝试编写不使用递归和goto语句的程序
在C和c++中,每个函数在使用之前都必须声明。这意味着在调用menu()
的函数之前,必须有一个menu声明。
否则,当编译器到达调用menu()
的代码时,它将不知道menu
的存在。
这段代码不能编译:
int main()
{
menu();
return 0;
}
void menu()
{
cout << "This is the menu functionn";
}
下面的代码将编译:
void menu(); /* menu declaration - this line tells the compiler that menu
* is a void function which takes no arguments
*/
int main()
{
menu();
return 0;
}
void menu()
{
cout << "This is the menu functionn";
}
要解决这个问题,请将void menu();
行放在calculator1
行之前。
- 错误:未在此范围内声明'reverse'
- 错误:"imread"未在此范围内声明
- 未在此范围内声明错误 'xy'
- Socklen_t未在此范围内声明
- 错误:'[' 之前预期的非限定 id 和错误:'users'未在此范围内声明
- "Main"已在当前范围内声明
- c++ 变量在宏的扩展中没有在这个范围内声明
- C++ 在编译过程中 strtok 函数 Eclipse 说没有在范围内声明?
- 'num1'未在此范围内声明
- 如何找到在本地范围内声明的变量的地址?
- NT状态未在此范围内声明
- 变量未在此范围内声明 数组线性搜索
- 包含文件中的 Typdef "未在此范围内声明"
- 'ClassName'和'ClassInstance'未在此范围内声明
- C++ 中的类之间的数据重新循环 - 错误:'<class name>'未在此范围内声明
- 代码作为 C 文件工作,但不作为C++文件,错误:'__builtin_types_compatible_p'未在此范围内声明
- 如何修复错误:"vreinterpretq_u32_f64"未在此范围内声明 - 在Android上使用Eigen构建
- 如何修复C++中的"arrStud未在此范围内声明"错误
- 错误:"SHGetKnownFolderPath"未在此范围内声明
- 错误:'Sprite'未在此范围内声明