类成员函数变量作用域

//Point.h
class Point
{
public:
 int x;
 int y;
 void output();
 void output(int x,int y);
};

 

//Point.cpp
#include "Point.h"
#include "iostream.h"
void main()
{
 Point pt;
 pt.x=5;
 pt.y=6;
 pt.output(3,5);
 pt.output();
}
void Point::output()
{
  cout<<x<<endl<<y<<endl;
  cout.operator <<("xya").operator <<(endl);
}
void Point::output(int x,int y)
{
 this->x=x;
 this->y=y;
}

成员函数中 出现和形参同名,变量是形参,一般出现在 右侧好理解,出现在左侧 也是一样的。

若和成员变量同名,则要用this 指针指向。

posted @ 2012-07-22 10:36  happyboy2  阅读(317)  评论(0编辑  收藏  举报