| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 638 人关注过本帖
标题:这个问题我怎么搞不懂?我的定义哪里出问题了???
只看楼主 加入收藏
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
快速回复:这个问题我怎么搞不懂?我的定义哪里出问题了???
数据加载中...
 
   



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

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