您的位置:首页 > 编程语言

孙鑫MFC视频第二节代码练习(二)类的this指针,类的派生

2014-09-08 19:16 190 查看
//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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: