this关键词 笔记

作用:
可以访问成员函数——属于某个类的函数或方法;
使用位置:在类中;
this.add(); this.a;
是什么:
一个指向当前对象实例的指针
代码示例:

	class Entity
	{
	public:
		int x, y;//this指向这里
		Entity(int x, int y)
		{
			this->x = x;
			this->y = y;
		}
	};

当this 作为参数传入时,会传入在这里设置的x和y的实例;

posted @ 2024-07-14 09:56  Wzline  阅读(2)  评论(0编辑  收藏  举报