需要一些家庭作業幫助。我是C++的新手,並且遇到了一個我不明白的錯誤。這裏是我的代碼:C++通過我的功能獲取錯誤
/*
* homework6.cpp
* Coder: omega9380
* Final Project
*/
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main() {
void welcomeScreen();
void printLine(int length);
welcomeScreen();
return 0;
}
void welcomeScreen() {
string userName = "";
string title1 = "CMPSC101 FINAL PROJECT";
string title2 = "CREATED BY: OMEGA9380";
// Welcome screen:
system("CLS");
cout << "/";
printLine(80);
cout << "\\" << endl;
cout << "|" << setw(81) << "|" << endl;
cout << "|" << setw(41 + (title1.length()/2)) << title1 << setw(40 - (title1.length()/2)) << "|" << endl;
cout << "|" << setw(41 + (title2.length()/2)) << title2 << setw(40 - (title2.length()/2)) << "|" << endl;
cout << "|" << setw(81) << "|" << endl;
cout << "\\";
printLine(80);
cout << "/" << endl;
}
void printLine(int length) {
for (int i = 0; i < length; i++) {
cout << "=";
}
}
錯誤是「error:'printLine'未在此範圍內聲明」。我在main()函數中聲明瞭「printLine()」,這還不夠嗎?還是我需要在每一個我打算使用它的函數中聲明函數名?爲了回答這個棘手的問題,我必須在這個最終的項目中使用函數。謝謝!!!
添加前置聲明或移動功能了。 –
更容易在任何其他功能之外聲明您的功能。 – aschepler
關鍵是「在此範圍內」void printLine(int length);'在'main'內聲明,所以它只能在'main'範圍內可見。 – user4581301