【发布时间】:2017-03-19 10:15:07
【问题描述】:
所以我今天正在学习一些课程,我对如何显示功能感到困惑
dateType::dateType()
{
cout<<"Object Created\n";
}
void dateType::setDate()
{
cout<<"Enter Month: ";
cin>>month;
cout<<endl;
cout<<"Enter Date: ";
cin>>day;
cout<<endl;
cout<<"Enter Year: ";
cin>>year;
cout<<endl;
}
.....
//other function declaration to access the private
.....
void dateType:: printdate()
{
cout<<"Month: "<<month<<endl;
cout<<"Date: "<<day<<endl;
cout<<"Year: "<<year<<endl;
cout<<"Leap Year: \n"<<endl;
}
dateType::~dateType()
{
cout<<"Object Deleted";
}
int main()
{
dateType().setDate();
dateType().printdate();
return 0;
}
现在当我运行程序时它工作正常,但问题是构造函数和破坏显示两次。
【问题讨论】:
-
完整代码不可用。
-
问问自己
dateType()在main中的实际作用。
标签: c++ class constructor destructor