蹲下站起来头晕眼黑:c++编程问题,请指教

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/12 16:05:03
#include <iostream>
using namespace std;
class date
{private: int year,month,day;
public:data(){}
data(int y,int m,int d)
{
year=y;
month=m;
day=d;
}
~date(){}
void add()
{
if (day==30)
{day=1;
if (month==12)
{month=1;year++;}
else month++;
}
else day++;

}
void print()
{
cout<<"year"<<year;
cout<<"month"<<month;
cout<<"day"<<day<<endl;
}
};
void main()
{
int month,year,day;
cout<<"year";cin>>year;
cout<<"month";cin>>month;
cout<<"day";cin>>day;
date d(year,month,day);
cout<<"the date you entered:";
d.print();
d.add();
cout<<"the data updated:";
d.print();
}

f:\c++\riqi\data\data.cpp(5) : warning C4183: 'data': member function definition looks like a ctor, but name does not match enclosing class
f:\c++\riqi\data\data.cpp(11) : warning C4183: 'data': member function definition looks like a ctor, but name does not match enclosing class
f:\c++\riqi\data\data.cpp(37) : error C2661: 'date::date' : no overloaded function takes 3 parameters
执行 cl.exe 时出错.

怎么回事啊?

你类的名字叫做date,而你的两个构造函数都叫data!改成date就行!

第5行应该是date(),你写成data()了
第11行也一样

还有这个构造函数,名字写错了,应该是date
public:data(){}
data(int y,int m,int d)
{
year=y;
month=m;
day=d;
}