多做一点,或许会有意外发现---VC60 到 VC2008

来源:互联网 发布:80端口是否打开 编辑:程序博客网 时间:2024/06/02 19:12

1。利用VC2008学习VC60 孙鑫的编著,代码如下

/*
 Date : 20091026
 For  : this pointer
 Page : p53/782
 Book : sunxin VC 60
*/

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

class point

public:
 double x;
 double y;
 point()
 {
  x = 0;
  y = 0;
 }
 point(double ix, double iy)
 {
  x = ix;
  y = iy;
 }

 void output()
 {
  cout << x << endl << y << endl;
 }
 void input(double ix, double iy) //the first
 {
  x = ix;
  y = iy;
 }
 /*
 void input(double x, double y)  //the second
 {
  x = x;
  y = y;
 }
 */
};

void main()
{
 char cEnd;
 point pt(5.6, 6.7);
 pt.input(12.2,25.6);
 pt.output();
 
 cout << "Please input anykey to end." << endl;
 cin >> cEnd;
 cout << " ";

}

2。运行the first 和 the second会有不同的结果,呵呵。原因自己好好分析一下,为什么?

3。另外不建议在代码中多处使用指针,否则代码健壮性会很差。

原创粉丝点击