//this指针指向的是对象的地址而不是类的地址
//2_3_1.h
#ifndef _2_2_1_H_
#define _2_2_1_H_
class Point
{
private:
int x;
int y;
public:
void output();
void output( int x,int y );
};
#endif
//2_3_1.cpp
#include<iostream.h>
#include"2_3_1.h"
void Point::output( int x,int y ) //this的作用之一:区别变量。
{
this->x = x;
this->y = y;
cout<<"x: "<<x<<" y: "<<y<<endl;
}
void Point::output()
{
x = 5;
y = 3;
cout<<"x: "<<x<<" y: "<<y<<endl;
}
void main()
{
Point pt;
pt.output();
pt.output(5,5);
}
孙鑫MFC视频第二节代码练习(二)类的this指针,类的派生
最新推荐文章于 2019-01-08 13:14:00 发布