我在第 30 行遇到错误 (const Date date2 = new Date(31, 12, 2012);)
错误消息是:请求从“日期*”转换为非标量类型“常量日期”
下面是我的源代码:
class Date
{
private :
int day ;
int month ;
int year ;
public :
Date(){
day = 1;
month = 1;
year = 2000;
}
Date(int d, int m, int y) : day(d), month(m), year(y){
}
int getDay () const { return day ;}
int getMonth () const { return month ;}
int getYear () const { return year ;}
};
int main ()
{
const Date date ;
const Date date2 = new Date(31, 12, 2012);
cout <<"The month is "<< date.getMonth()<< endl ;
cout << " The month is "<<date2.getMonth()<< endl ;
return 0;
}