这个问题我怎么搞不懂?我的定义哪里出问题了???
d:\program files\microsoft visual studio 10.0\练习项目文件夹\switch\switch\switchhead.cpp(86): error C2084: 函数“void GradeBook::displayGradeReport(void)”已有主体1> d:\program files\microsoft visual studio 10.0\练习项目文件夹\switch\switch\switchhead.h(12) : 参见“displayGradeReport”的前一个定义
swichhead.h代码如下:
#include<string>
using std::string;
class GradeBook
{
public:
GradeBook( string );
void setCourseName( string );
string getCourseName();
void displaynMessage();
void inputGrades();
void displayGradeReport();
private:
string courseName;
int aCount;
int bCount;
int cCount;
int dCount;
int fCount;
};
switchhead.cpp代码如下:
#include<iostream>
using std::cout;
using std::cin;
using std::endl;
#include"switchhead.h"
GradeBook::GradeBook( string name )
{
setCourseName( name );
aCount=0;
bCount=0;
cCount=0;
dCount=0;
fCount=0;
}
void GradeBook::setCourseName( string name )
{
if ( name.length()<= 25 )
courseName=name;
else
{
courseName=name.substr( 0,25 );
cout<<"Name \"" << name << "\" exceeds maximum length (25),\n"
<< "Limiting courseName to first 25 characters.\n"<< endl;
}
}
string GradeBook::getCourseName()
{
return courseName;
}
void GradeBook::displayGradeReport()
{
cout<< "Welcome to the grade book for\n" << getCourseName() <<"!\n"<<endl;
}
void GradeBook::inputGrades()
{
int grade;cout << "Enter the letter grades." << endl<< "Enter the EOF character to end input."<< endl;
while( ( grade - cin.get() ) != EOF)
{
switch ( grade )
{
case 'A':
case 'a':
aCount++;
break;
case 'B':
case 'b':
bCount++;
break;
case 'C':
case 'c':
cCount++;
break;
case 'D':
case 'd':
dCount++;
break;
case 'F':
case 'f':
fCount++;
break;
case '\n':
case '\t':
case ' ':
break;
default:
cout << "Incorrect letter grade enterde."<< " Enter a new grade."<< endl;
break;
}
}
}
void GradeBook::displayGradeReport()
{
cout << "\n\nNumber of students who received each letter grade:"
<< "\nA: "<< aCount
<< "\nB: "<< bCount
<< "\nC: "<< cCount
<< "\nD: "<< dCount
<< "\nF: "<< fCount
<< endl;
}