Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4274834
  • 博文数量: 1148
  • 博客积分: 25453
  • 博客等级: 上将
  • 技术积分: 11949
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-06 21:14
文章分类

全部博文(1148)

文章存档

2012年(15)

2011年(1078)

2010年(58)

分类: C/C++

2011-07-07 09:23:48

工程代码:  page30.rar  

《VC++ 深入详解》

  1. #include <iostream>

  2. using namespace std;

  3. class point
  4. {
  5. public:
  6.         int x;
  7.         int y;

  8.         point()//名字与 类名字一样
  9.         {
  10.             x = 3; //构造函数
  11.             y = 4;
  12.         }
  13.         point(int a, int b)
  14.         {
  15.             x = a;
  16.             y = b;
  17.         }

  18.         ~point()//名字与 类名字一样
  19.         {
  20.             cout << "bye the world" << endl;
  21.         }
  22.     
  23.         void output()
  24.         {
  25.             cout << x << endl << y << endl;
  26.         }
  27.         void input()
  28.         {
  29.             cin >> x;
  30.             cin >> y;
  31.         }

  32.         void input(int x, int y)
  33.         {
  34.             this->x = x;
  35.             this->y = y;
  36.         }
  37. };

  38. int main(void)
  39. {
  40. //    point pt;//自动使用无参数构造函数 point()
  41.     point pt(5,2); //构造函数初始化
  42.     pt.output();

  43.     pt.input(); //定义标准输入
  44.     pt.output();

  45.     pt.input(1,0);//
  46.     pt.output();
  47.     return 0;
  48. }




阅读(556) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~