在c+中从函数到函数传递参数+; 我是C++新手,我正在做一个象棋游戏。< / P>

在c+中从函数到函数传递参数+; 我是C++新手,我正在做一个象棋游戏。< / P>,c++,C++,这是我要做的主菜单,但我遇到了麻烦。以下是我代码的要点: int mMenu(int&, char&, bool&, char&); int main(char&) { int choice; char sure; bool quit = false; char ctrl // used for the control from main menu to main() mMenu (choice, sure,

这是我要做的主菜单,但我遇到了麻烦。以下是我代码的要点:

int mMenu(int&, char&, bool&, char&);

int main(char&) 
{
    int choice;
    char sure;
    bool quit = false;

    char ctrl // used for the control from main menu to main()

    mMenu (choice, sure, quit);

    do
    {
        if (ctrl == a)
            NewGame();
        else if (ctrl == b)
            LoadGame();
        else
            quit = true;
    }
    while (quit == true);

    return 0;
}


int mMenu(int& choice, char& sure, bool& quit, char& ctrl,)
{
    do
{
    cout << "                           Chess                               "
         << "------------------------ Main Menu ------------------------\n"
         << "Please choose what operation you'd like to perform from the         menu below\n\n"
         << "1. New Game.\n"
         << "2. Load Game.\n"
         << "Exit.\n"
         << "Your choice: ";
    cin >> choice;

    if (choice == 1)
    {
        cout << "Are you sure you wish to start a new game? (Y/N) ";
        cin >> sure;
        if (sure != 'Y')
            clrscr();
        else
        {
            ctrl = a;
            quit = true;
    }
    else if (choice == 2)
    {
        ctrl = b;
        quit = true;
    }
    else if (choice == 3)
    {
        cout << "Are you sure you wish to exit? (Y/N) ";
        cin >> sure;
        if (sure != 'Y')
            clrscr();
        else
        {
            quit = true;
            ctrl = c;
        }
    }
    }
}
while (quit = true);

return ctrl;
}
intmmenu(int&,char&,bool&,char&);
int main(char&)
{
智力选择;
char sure;
bool-quit=false;
char ctrl//用于从主菜单到主()的控件
mMenu(选择、确定、退出);
做
{
如果(ctrl==a)
新游戏();
else if(ctrl==b)
LoadGame();
其他的
退出=真;
}
while(quit==true);
返回0;
}
int-mMenu(int&choice,char&sure,bool&quit,char&ctrl,)
{
做
{

cout它实际上不需要3个参数,需要4个:

int mMenu(int& choice, char& sure, bool& quit, char& ctrl,)
            // << the "," in the end 
            // shouldn't be there
intmmenu(int&choice,char&sure,bool&quit,char&ctrl,)

//这是因为您将mMenu定义为接受四个参数,但仅使用三个参数调用它

mMenu (choice, sure, quit);

错的是,mMenu不接受3个参数,而是接受4个参数

有两种方法可以编译此文件:

  • 更改mMenu,使其包含3个参数
  • 使用当前的4个参数调用mMenu

您定义了一个包含4个参数的函数,但在尝试调用它时只提供了3个参数。@OliCharlesworth将其作为答案:)
int-mMenu(int&choice,char&sure,bool&quit,char&ctrl=0)
最后一个默认值的参数注意:
int-main(char&)
全局命名空间中的不应为托管实现干净地编译。注意2:
char-ctrl
缺少分号,因此不应编译。OMG!我真是个白痴XD!我想这是您回答过的最愚蠢的问题了!非常感谢您:L
mMenu (choice, sure, quit);