Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7651343
  • 博文数量: 961
  • 博客积分: 15795
  • 博客等级: 上将
  • 技术积分: 16612
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-07 14:23
文章分类

全部博文(961)

文章存档

2016年(1)

2015年(61)

2014年(41)

2013年(51)

2012年(235)

2011年(391)

2010年(181)

分类: C/C++

2011-03-29 10:25:12

  1. /****************************************************
  2. * 文件名:例八
  3. * 功能:析构函数
  4. * 说明:析构函数可以由程序调用,也可以由系统自动调用
  5. * 时间:2011-3-29      --Lzy
  6. /****************************************************/
  7. #include <iostream.h>            //观察析构函数调用顺序


  8. class Elipse
  9. {
  10. private:
  11.     double x, y, a, b;

  12. public:
  13.     Elipse();
  14.     Elipse(double, double, double, double);
  15.     ~Elipse();        //析构函数

  16.     void printf();
  17. };

  18. Elipse::Elipse()
  19. {
  20.     cout<<"缺省构造函数"<<endl;
  21.     x = y = a = b = 0;
  22. }

  23. Elipse::Elipse(double x1, double y1, double a1, double b1)
  24. {
  25.     cout<<"带参数构造函数"<<endl;
  26.     x = x1; y = y1; a = a1; b = b1;
  27. }

  28. Elipse::~Elipse()
  29. {
  30.     cout<<"析构函数";
  31.     cout<<"("<<x<<" ,"<<y<<")"<<" a="<<a<<" b="<<b<<endl;
  32. }

  33. void Elipse::printf()
  34. {
  35.     cout<<"("<<x<<" ,"<<y<<")"<<" a="<<a<<" b="<<b<<endl;
  36. }

  37. void main()
  38. {
  39.     Elipse s1, s2(100,200,300,400);
  40.     s1.printf();
  41.     s2.printf();

  42.     cout<<"*********************************"<<endl;
  43. }
阅读(1291) | 评论(0) | 转发(2) |
给主人留下些什么吧!~~