我正在處理這個項目,這是我第一次使用makefile。使用makefile編譯C++錯誤,無法轉換main()::
,我得到的錯誤是:
HW1.cpp:45:55: error: could not convert ‘Student1’ from ‘main()::Student’ to ‘Student’
主文件:
#include "header.h"
#include "function.h"
main()
{
int input = 0;
bool loop = 1;
#include "list.cpp"
ResetArray(arrayCou, arrayStu);
while (loop)
{
cout << "cmd> ";
cin >> input;
switch (input)
{
case 1:
AddCourse(&Course1, arrayCou);
break;
case 2:
AddStudent(&Student1, arrayStu);
break;
case 3:
AddStuCourse(&Student1, &Course1, arrayStu, arrayCou);
break;
case 4:
AddGrade(&Student1, &Course1, arrayStu, arrayCou);
break;
case 5:
PrintCourse(&Student1, &Course1, arrayStu, arrayCou);
break;
case 6:
PrintStudent(&Student1, &Course1, arrayStu, arrayCou);
break;
case 7:
PrintStuCourse(&Student1, &Course1, arrayStu, arrayCou);
break;
case 8:
AvgStuCourse(&Student1, &Course1, arrayStu, arrayCou);
break;
case 9:
loop = 0;
break;
default:
break;
}
}
}
函數聲明:
#include "header.h"
void ResetArray(Course arrayCou[][101][5], Student arrayStu[][3]);
void AddCourse(Course Course1, Course arrayCou[][101][5]);
void AddStudent(Student Student1, Student arrayStu[][3]);
void AddStuCourse(Student Student1, Course Course1, Student arrayStu[][3], Course arrayCou[][101][5]);
void AddGrade(Student Student1, Course Course1, Student arrayStu[][3], Course arrayCou[][101][5]);
void PrintCourse(Student Student1, Course Course1, Student arrayStu[][3], Course arrayCou[][101][5]);
void PrintStudent(Student Student1, Course Course1, Student arrayStu[][3], Course arrayCou[][101][5]);
void PrintStuCourse(Student Student1, Course Course1, Student arrayStu[][3], Course arrayCou[][101][5]);
void AvgStuCourse(Student Student1, Course Course1, Student arrayStu[][3], Course arrayCou[][101][5]);
頭文件:
#include <iostream>
#include <string.h>
#include <cstring>
#include <iomanip>
using namespace std;
const int MAXSIZE = 101;
struct Student
{
string ID;
string name;
string majors;
};
struct Course
{
string ID;
string title;
string department;
double grade;
};
Student arrayStu[101][3];
Course arrayCou[101][101][5];
Course Course1;
Student Student1;
函數定義非常長,所以我不想包含所有的函數,但是有什麼方法可以修復makefile嗎?它說主函數中每次使用Student1或Course1時出現同樣的錯誤。
應該是'INT主要()' –
你忘了主要返回類型。 – NathanOliver
順便說一句,顯示你的'Makefile'或者至少是編譯命令'#include「list.cpp」' - 包括一個函數裏面的'cpp'? –