C++类中的变量和构造函数
来源:互联网 发布:怎么用网络看电视直播 编辑:程序博客网 时间:2024/06/05 06:21
今天看的一道题
#include"iostream"
using namespace std;
class CCounter
{
int value;
public:
CCounter();
CCounter(int val);
~CCounter();
};
class CExample
{
int value;
public:
CCounter car;
CExample();
CExample(int val);
void Display();
~CExample();
};
CCounter::CCounter()
{
cout<<"ccounter Constructorl"<<endl;
value=0;
}
CCounter::CCounter(int val)
{
cout<<"CCounter constructor2"<<endl;
value=val;
}
CCounter::~CCounter()
{
cout<<"CCounter Destructor"<<endl;
}
CExample::CExample()
{
cout<<"CExample constructorl"<<endl;
value=0;
}
CExample::CExample(int val)
{
cout<<"CExamPle Constructorl"<<endl;
value=val;
}
void CExample::Display()
{
cout<<"value=" <<value<<endl;
}
CExample::~CExample()
{
cout<<"CExample Destructor"<<endl;
}
void main()
{
CExample e(2);
e.Display();
}
输出结果是:
CCounter Constructor
CExample Constructor
Value=2
CExample Destmctor
CCounter Destructor
经过实验确实是这样:C++是先构造其变量,然后再进入构造函数
- C++类中的变量和构造函数
- C/C++中的静态变量和函数
- C++中的拷贝构造函数和拷贝赋值操作符+const成员变量初始化(5)---《Effective C++》
- JOptionPane_构造函数和变量
- C语言中的构造函数
- Objective-C中的便利初始化函数和便利构造器
- 初识c#---继承和继承关系中的构造函数
- C#Static类和Static构造函数
- java类中的构造函数和构造代码块
- Python的构造函数和析构函数 对象的变量和类的变量不一样
- C++类成员变量和构造函数初始化
- java反射:获取类的成员变量和构造函数
- 关于'类的构造函数'和'该类的成员变量构造函数'调用的先后次序
- C/C++中的static变量和static函数
- 在C中引用C++语言中的函数和变量
- c语言中的static变量和static函数
- C语言中的static变量和static函数
- C/C++中的 static 变量和 static 函数
- win32程序启动的过程和启动速度的优化
- poj.1789
- SharePoint 2010/2013 通过List Item的内容菜单(BCD)来拷贝Item
- JavaEE的13种核心技术
- poj2387
- C++类中的变量和构造函数
- tcpdump
- java Struct
- 产品经理总结运营过程中9大心得
- MongoDB的java版本驱动(译文)
- UniGUI的TUniLoginForm窗口自定义背景色
- 1074. Reversing Linked List (25)
- Android 模拟器
- 实用SQL语句大全