12_1.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:
C#编程
开发平台:
Visual C++
- //12_1
- #include <iostream.h>
- class MyClass{
- public:
- MyClass();
- MyClass(int);
- ~MyClass();
- void Display();
- protected:
- int number;
- };
- MyClass::MyClass(){ cout <<"Constructing normally.n"; }
- MyClass::MyClass(int m):number(m)
- {
- cout <<"Constructing with a number: " <<number <<endl;
- }
- void MyClass::Display(){ cout <<"Display a number: " <<number <<endl; }
- MyClass::~MyClass(){ cout <<"Destructing.n"; }
- void main()
- {
- MyClass obj1;
- MyClass obj2(20);
- obj1.Display();
- obj2.Display();
- }