2013-07-14 74 views
0

我想在頭文件中使用結構類型,然後在我的主文件初始化,但繼續得到錯誤:結構類型在頭文件錯誤

「爲號召「gradingStudent沒有匹配功能: :gradingStudent()」「

HeaderFile.h

#ifndef HEADERFILE_H 
#define HEADERFILE_H 

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

using namespace std; 

struct gradingStudent 
{ 

    string studentName; //student's name 

    int amtGradesHW; 
    int amtGradesPro; 
    int amtGradesExam; //number of homework programs 

    float perTotHW; 
    float perTotPro; 
    float perTotExams; //percent the grade is worth 

    float HWGradeRecieved; 
    float ProGradeRecieved; 
    float ExamGradeRecieved; //points recieved 

    float TotalPercentage; //final grade recieved 

    char X; //letter grade 

    string wittyComment; //comment on grade 

    int const MAX; 

    }; 
int openFiles(ifstream&, ofstream&); 

#endif 

編程Assignment.cpp

#include <iostream> 
#include <fstream> 
#include <string> 
#include "HeaderFile.h" 

using namespace std; 

int main(){ 



ifstream inFile; //input file variable 
ofstream outFile; //output file stream 

gradingStudent grades; //intialize my struct 

//Test If files can be opened 
if(!openFiles(inFile, outFile)){ 
cout << "...exiting " << endl; 
system("pause"); 
         }//end if 





}//end main 

/* 
* Input: ifstream and ofstream 
* Return Type: int 
* 
* OpenFiles will ask the user for the files to be opened and check if they are able to   be opened 
    * usage: openFiles(inFile, OutFile) 
    **/ 

    int openFiles(ifstream& inD, ofstream& outD){ 

string inFileName, outFileName; 

cout << "Please enter the name of the file to be read: " << endl; 
cin >> inFileName; 
cout << " " << endl; 

inD.open(inFileName.c_str()); //open this file 
if (!inD) 
{ 
     cout << "ERROR. THE INPUT FILE: " << inFileName << " WAS UNABLE TO BE  OPENED!"  << endl ; 
     cout << "  " << endl;  

     return 0; 
      }//end input if fail state 


    cout << "Please enter the name of the file to be written: " << endl; 
    cin >> outFileName; 
    cout << " " << endl;     

     outD.open(outFileName.c_str()); //open this file 

     if (!outD) 
{ 
     cout << "ERROR. THE OUTPUT FILE: " << outFileName << " WAS UNABLE TO BE   OPENED!" << endl ; 
     cout << "  " << endl;  

     return 0; 
      }//end output if fail state  

}//end open file 

任何幫助將不勝感激

回答

0

你有一個const(和非static)成員變量(MAX),它需要顯式初始化。因此你必須明確地爲你的類定義一個構造函數。

+0

謝謝你的工作。 – user2445852