[英]Class can't reach int function from main C++
我正在編寫程序,但是由於某些原因,我無法從main達到游戲功能,除了我會遇到以下錯誤:
20:23: error: expected primary-expression before ']' token
這是代碼:
#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;
}
任何幫助,將不勝感激,謝謝!
在main()
函數中, gameply
調用語法是錯誤的!
gameplay(suitcase[], outputFile);
應該只是:
gameplay(suitcase, outputFile);
^
removed []
函數聲明中需要[]
,但在調用函數時不需要。
由於您已經將手提箱定義為數組,因此在將手提箱傳遞到函數中時不必說出手提箱[]。 (或者在其他任何地方引用它)
gameplay(suitcase[], outputFile);
應該只是:
gameplay(suitcase, outputFile);
這應該工作!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.