C++有处错误,请高手改正。

来源:百度知道 编辑:UC知道 时间:2024/06/09 03:34:34
#include<iostream.h>
class Date
{
public:
Date(int y,int m,int d);
Date();
~Date();
void setDate(int y,int m,int d);
void showDate();
private:
int year;
int month;
int day;
};
Date::Date(int y,int m,int d)
{
cout<<"constructing..."<<endl;
year=y;
month=m;
day=d;
}
Date::Date()
year=2007;
month=1;
day=1;
}
Date::~Date()
{
cout<<"destruting..."<<endl;
}
void Date::setDate(int y,int m,int d)
{
year=y;
month=m;
day=d;
}
inline void Date::showDate()
{
cout<<year<<"."<<month<<"."<<day<<endl;
}
void main()
{
Date date1
cout<<"Date1 output1:"<<endl;
date1.showDate();
date1.setDate(2007,5,9);
cout<<"

Date date1
这行掉了分号。

没什么大的错误 修改后:
#include<iostream.h>
class Date
{
public:
Date(int y,int m,int d);
Date();
~Date();
void setDate(int y,int m,int d);
void showDate();
private:
int year;
int month;
int day;
};
Date::Date(int y,int m,int d)
{
cout<<"constructing..."<<endl;
year=y;
month=m;
day=d;
}
Date::Date()
{
year=2007;
month=1;
day=1;
}
Date::~Date()
{
cout<<"destruting..."<<endl;
}
void Date::setDate(int y,int m,int d)
{
year=y;
month=m;
day=d;
}
inline void Date::showDate()
{
cout<<year<<"."<<month<<"."<<day<<endl;
}
void main()
{
Date date1 ;
cout<<"Date1 output1:&quo