定义一个类Demo,有构造函数、析构函数和成员函数show(),其中show()根据样例的格式输出具体属性值。该类只有一个int类型的成员。
Home | Web Board | ProblemSet | Standing | Status | Statistics |
定义一个类Demo,有构造函数、析构函数和成员函数show(),其中show()根据样例的格式输出具体属性值。该类只有一个int类型的成员。
输入只有一个整数,int类型范围内。
见样例。
#include<iostream> using namespace std; class Demo{ public: int x; Demo(int a=0):x(a){cout<<"A data "<<x<<" is created!"<<endl;} ~Demo(){cout<<"A data "<<x<<" is erased!"<<endl;} void show(){cout<<"This is data "<<x<<endl;} }; int main() { Demo tmp(10), tmp2; int d; cin>>d; Demo tmp3(d); tmp.show(); tmp2.show(); tmp3.show(); return 0; }
原文:http://www.cnblogs.com/auto1945837845/p/5516488.html