[求助]重载构造函数~
#include<iostream.h>
class Tdate
{
public:
Tdate(){init(4,15,1995);}
Tdate(int d){init(4,d,1996);}
Tdate(int m,int d){init(m,d,1997);}
Tdate(int m, int d,int y){init(m,d,y);}
protected:
int month;
int day;
int year;
void init(int m,int d,int y)
{
month=m;
day=d;
year=y;
cout<<month<<"/"<<day<<"/"<<year<<endl;
}
};
void main()
{
Tdate aday;
Tdate bday(10);
Tdate cday(1,12);
Tdate dday(1,2,1998);
}
红色部分因为上面类定义的时候虽没参数,但有括号,这里为何不加括号?一加括号就不输出~