| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1433 人关注过本帖
标题:运算符重载,看看这个程序哪里错了?
只看楼主 加入收藏
家力掠
Rank: 2
等 级:论坛游民
帖 子:52
专家分:16
注 册:2015-6-28
结帖率:41.18%
收藏
已结贴  问题点数:10 回复次数:2 
运算符重载,看看这个程序哪里错了?
-------date.h----------------
程序代码:
#ifndef __DATE__
#define __DATE__

class Date;

class Date
{
public:
    Date(int y = 0, int m = 0, int d = 0) : year(y), month(m), day(d) {  }
    int year() const { return year; }
    int month() const { return month; }
    int day() const { return day; }
private:
    int year, month, day;
};

inline bool
operator > (const Date& d1, const Date& d2)
{
    bool flag = 0;
    if (d1.year() > d2.year())  flag = 1;
    else if (d1.year() == d2.year()) {
        if (d1.month() > d2.month())    flag = 1;
        else if (d1.month() == d2.month()) {
            if (d1.day() > d2.day())    flag = 1;
            else;
        }
        else;
    }
    else;

    return flag;
}

inline bool
operator == (const Date& d1, const Date& d2)
{
    bool flag = 0;
    if (d1.year() == d1.year() && d1.month() == d2.month() && d1.day() == d2.day())
        flag = 1;

    return flag;
}

inline bool
Date::operator < (const Date& d2)
{
    bool flag = 0;
    if (d1.year() < d1.year())  flag = 1;
    else if (d1.year() == d2.year()) {
        if (d1.month() < d2.month())    flag = 1;
        else if (d1.month() == d2.month()) {
            if (d1.day() < d2.day())    flag = 1;
            else;
        }
        else;
    }
    else;

    return flag;
}
#endif          //end __Date__


----------date_test.cpp-----------------
程序代码:
#include <iostream>
#include "date.h"

using namespace std;

int main()
{
    Date d1(2011,1,1);
    

    return 0;
}


.\date_test.cpp: In function 'int main()':
.\date_test.cpp:8:5: error: 'Date' was not declared in this scope
     Date d1(2011,1,1);
请教这个是什么问题?
2016-09-28 08:55
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:10 
__DATE__ 是C/C++的预置宏,换个名字吧
2016-09-28 09:16
家力掠
Rank: 2
等 级:论坛游民
帖 子:52
专家分:16
注 册:2015-6-28
收藏
得分:0 
回复 2楼 rjsp
非常感谢。难怪我一直debug不出来。
2016-09-28 17:30
快速回复:运算符重载,看看这个程序哪里错了?
数据加载中...
 
   



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

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