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

本文通过一个简单的Point类实例介绍了如何使用VC2008进行编程,并对比了不同成员函数实现方式带来的效果差异。文章还强调了过度使用指针可能导致的问题。

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。另外不建议在代码中多处使用指针,否则代码健壮性会很差。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值