标题:这个问题我怎么搞不懂?我的定义哪里出问题了???
只看楼主
GeneralJing
Rank: 2
等 级:论坛游民
帖 子:30
专家分:15
注 册:2011-9-26
 问题点数:0 回复次数:3 
这个问题我怎么搞不懂?我的定义哪里出问题了???
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;
}
搜索更多相关主题的帖子: microsoft 文件夹 include public visual 
2011-09-30 11:18
GeneralJing
Rank: 2
等 级:论坛游民
帖 子:30
专家分:15
注 册:2011-9-26
得分:0 
问题出现在displayGradeReport这个函数上,可我感觉我这个函数在类的声明和定义上没有错误啊,为什么编译会失败呢?
2011-09-30 11:27
specilize
Rank: 4
等 级:业余侠客
帖 子:126
专家分:247
注 册:2011-2-20
得分:0 
回复 2楼 GeneralJing
不是吧,displayGradeReport定义两次还看不出来
2011-09-30 12:58
GeneralJing
Rank: 2
等 级:论坛游民
帖 子:30
专家分:15
注 册:2011-9-26
得分:0 
回复 3楼 specilize
非常感谢,哈哈 刚才太粗心了,感激不尽!
2011-09-30 13:37



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-351344-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.111483 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved