标题:钱能C++书中重载成员函数编译出错,请教一下。
取消只看楼主
cookies5000
Rank: 2
等 级:论坛游民
帖 子:33
专家分:48
注 册:2009-10-25
结帖率:100%
已结贴  问题点数:20 回复次数:2 
钱能C++书中重载成员函数编译出错,请教一下。
#include<iostream>
#include<iomanip>
using namespace std;

class Date
{
    int y,m,d;
   
public:
    void set(int year,int month,int day);
    void set(string &s);
    bool isleapyear();
    void print();
};
//
void Date::set(int year,int month,int day)
{
    y=year;
    m=month;
    d=day;
}
//
void Date::set(string &s)
{
    y=atoi(s.substr(0,4).c_str());
    m=atoi(s.substr(5,2).c_str());
    d=atoi(s.substr(8,2).c_str());
}
//
void Date::print()
{
    cout<<setfill('0');
    cout<<setw(4)<<y<<'-'<<setw(2)<<m<<'-'<<setw(2)<<d<<'\n';
    cout<<setfill(' ');
}
//
bool Date::isleapyear()
{
    return(y%4==0 && y%100!=0) || (y%400==0);
}
//
void main()
{
    Date d,e;
    d.set(2008,12,16);
    e.set("2008-12-08");    //line 46
    e.print();
    if(d.isleapyear())
    d.print();
}
编译报错 line 46:error C2275: 'string' : illegal use of this type as an expression
搜索更多相关主题的帖子: 重载 编译 成员 函数 
2009-10-25 11:23
cookies5000
Rank: 2
等 级:论坛游民
帖 子:33
专家分:48
注 册:2009-10-25
得分:0 
谢谢楼上哥们,可我编译还是不行啊。。。
2009-10-25 12:23
cookies5000
Rank: 2
等 级:论坛游民
帖 子:33
专家分:48
注 册:2009-10-25
得分:0 
sorry ,刚才只改一处。。。是可以编译通过。。。请问一下为什么要这么改?
2009-10-25 12:26



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




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

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