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。另外不建议在代码中多处使用指针,否则代码健壮性会很差。
本文通过一个简单的Point类实例介绍了如何使用VC2008进行编程,并对比了不同成员函数实现方式带来的效果差异。文章还强调了过度使用指针可能导致的问题。

被折叠的 条评论
为什么被折叠?



