简体   繁体   English

类无法从主C ++到达int函数

[英]Class can't reach int function from main C++

I'm writing a program, however for some reason I can't reach the gameplay function from main, except I just get the following errors: 我正在编写程序,但是由于某些原因,我无法从main达到游戏功能,除了我会遇到以下错误:

20:23: error: expected primary-expression before ']' token

Here's the code: 这是代码:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int gameplay (int suitcase[], ofstream outputFile)
{
    cout << "Here?";
    return 0;
}
int main()
{
    const int ARRAY_SIZE = 10;
    int suitcase [ARRAY_SIZE] = {1, 10, 100, 1000, 10000, 100000, 1000000, 0, 0, 0};
    ofstream outputFile;
    outputFile.open ("players.txt");
    gameplay(suitcase[], outputFile);
    outputFile.close ();

    return 0;
}

Any help would be appreciated, thanks! 任何帮助,将不胜感激,谢谢!

In main() function call syntax of gameply is wrong! main()函数中, gameply调用语法是错误的!

gameplay(suitcase[], outputFile);

should be just: 应该只是:

gameplay(suitcase, outputFile);
                 ^
                  removed []

[] needed in function declaration but not at the time when you call function. 函数声明中需要[] ,但在调用函数时不需要。

Since you already defined suitcase as an array, you shouldn't have to say suitcase[] when you pass it into the function. 由于您已经将手提箱定义为数组,因此在将手提箱传递到函数中时不必说出手提箱[]。 (or refer to it anywhere else, for that matter) (或者在其他任何地方引用它)

gameplay(suitcase[], outputFile); 

should just be: 应该只是:

gameplay(suitcase, outputFile);

This should work! 这应该工作!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM