错误:预期的非限定id错误:含义和修复? 我只是学习了C++,从Python 3和QBasic中出来,我很难读懂编译器的错误并理解它们,这使得调试变得困难。

错误:预期的非限定id错误:含义和修复? 我只是学习了C++,从Python 3和QBasic中出来,我很难读懂编译器的错误并理解它们,这使得调试变得困难。,c++,compiler-errors,C++,Compiler Errors,我遇到的问题是,我一直在拉编译错误: 错误:应为非限定id 这发生在第10行和第18行 我正在尝试使用linuxs的g++编译此程序: g++ proto.cpp -o prototype 该程序的代码如下所示 #include <iostream> #include <string> using namespace std; //Declaring Functions //Trouble Function int mult ( double x, double y

我遇到的问题是,我一直在拉编译错误:

错误:应为非限定id

这发生在第10行和第18行

我正在尝试使用linuxs的g++编译此程序:

g++ proto.cpp -o prototype
该程序的代码如下所示

#include <iostream>
#include <string>
using namespace std;
//Declaring Functions

//Trouble Function
int mult ( double x, double y );
{
    return x * y;
}

//Trouble Function
int dive ( double x, double y );
{
    if ( y == 0 )
    {
        cout<<"Error, cannot divide by zero.\n";
        return;
    }
    else
    {
        return x / y;
    }
}

//This error doesn't occur beyond this point.
int plus ( double x, double y );
{
    return x + y;
}
int min ( double x, double y );
{
    return x - y;
}
//End of global declarations.
//I would have made them local functions if not
//for an entirely set of unrelated problems.

int main()
{
    cout<<"Please enter two numbers.\n"<<"\n";
    int num1;
    int num2;
    cin>>num1;
    cin>>num2;
    string returnz = "<unknown>";
    while ( returnz != "no" )
    {
        cout<<"What would you like to do with the numbers>\n";
        cout<<'\n'<<"Enter ( mult ) to multiply, ( min ) to subtract, ( plus ) to add, and ( dive ) to divide.\n";
        getline( cin, returnz, '\n' );
        if ( returnz == "mult" )
        {
            double result = mult ( num1, num2 );
            cout<<num1<<" * "<<num2<<" = "<<result<<"\n";
            continue;
        }
        else if ( returnz == "dive" )
        {
            double rest = dive ( num1, num2 );
            cout<<num1<<" / "<<num2<<" = "<<rest<<"\n";
            continue;
        }
        else if ( returnz == "plus" )
        {
            double res = plus ( num1, num2 );
            cout<<num1<<" + "<<num2<<" = "<<res<<"\n";
            continue;
        }
        else if ( returnz == "min" )
        {
            double re = min ( num1, num2 );
            cout<<num1<<" - "<<num2<<" = "<<re<<"\n";
            continue;
        }
        else
        {
            break;
        }
    }
}

如@user657267所述,在声明函数及其实现时,请去掉分号。如果你有

int some_function(int a, int b);
上面的主要功能和下面的主要功能的实现

int some_function(int a, int b) {
    //something happens here
     return a;
}

那没关系。实现也可以在main之上,然后您不必编写定义函数的第一行。定义或实现必须高于主的原因是C或C++,否则将不能看到函数,否则将抛出和错误。

<代码> int Mult(double x,double y);<代码>去掉分号。使用名称空间std的另一个原因是
是坏的。重命名您的
min()
函数。另外,当您使用双精度运算时,为什么要返回整数?“关于如何用更有效的代码实现这一点的建议也很受欢迎,我们将不胜感激。”——查找简单的编程问题,并在网上发布答案。不要先看答案,但是如果你有一些你认为有效但没有的东西,那么看看答案,看看你做了什么不同。嗨。发布一个-强调最小的。我们也看不到原始的行号,所以“错误发生在X行”在这里是无用的信息。明白了。我会修改的,谢谢。
int some_function(int a, int b) {
    //something happens here
     return a;
}