码迷,mamicode.com
首页 > 其他好文 > 详细

理解继承中的构造器和析构器

时间:2015-08-10 09:24:14      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:

 1 #include <iostream>
 2 #include <string>
 3 
 4 using namespace std;
 5 
 6 class FatherClass
 7 {
 8 public:
 9     FatherClass();
10     ~FatherClass();
11 };
12 
13 FatherClass::FatherClass()
14 {
15     cout << "this is FatherClass constructor"<<endl;
16 }
17 
18 FatherClass::~FatherClass()
19 {
20     cout << "this is FatherClass finalizer"<<endl;
21 }
22 
23 class ChildClass:public FatherClass
24 {
25 public:
26     ChildClass();
27     ~ChildClass();
28 };
29 
30 ChildClass::ChildClass()
31 {
32     cout << "this is ChlidClass constructor"<<endl;
33 }
34 
35 ChildClass::~ChildClass()
36 {
37     cout << "this is ChildClass finalizer"<<endl;
38 }
39 
40 int main()
41 {
42     ChildClass a;
43     cout << "finished"<<endl;
44     return 0;
45 }

执行结果:

技术分享

理解继承中的构造器和析构器

标签:

原文地址:http://www.cnblogs.com/raichen/p/4717028.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!