我對C++比較陌生,並且正忙於功能。 我似乎無法弄清楚爲什麼下面的代碼不工作, 任何幫助將不勝感激。我的功能出了什麼問題
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main() {
movieOutput("Hello");
return 0;
}
//This is just for a little extra versatility
int movieOutput(string movieName,int aTix = 0,int cTix = 0,float grPro = 0.0,float nePro = 0.0,float diPro = 0.0){
//I don't understand whether I should declare the arguments inside the
//functions parameters or in the function body below.
/*string movieName;
int aTix = 0, cTix = 0;
float grPro = 0.0, nePro = 0.0, diPro = 0.0;*/
cout << "**********************Ticket Sales********************\n";
cout << "Movie Name: \t\t" << movieName << endl;
cout << "Adult Tickets Sold: \t\t" << aTix << endl;
cout << "Child Tickets Sold: \t\t" << aTix << endl;
cout << "Gross Box Office Profit: \t" << grPro << endl;
cout << "Net Box Office Profit: \t" << nePro << endl;
cout << "Amount Paid to the Distributor: \t" << diPro << endl;
return 0;
}
構建的錯誤我得到
`Build:(compiler: GNU GCC Compiler)
|line-8|error: 'movieOutput' was not declared in this scope|
Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|`
移動的定義主要在使用的函數 –
之下,因爲@JosephYoung建議或爲該函數寫一個前向聲明行,「在」第一個函數「之上」調用它(這裏是main) – Dilettant
謝謝你們,你們都幫我弄明白了! – DaltonM