这个指针在C ++中 [英] this pointer in C++

查看:71
本文介绍了这个指针在C ++中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对此指针的使用感到困惑..

Confused about the usage of this pointer..

在&mbsp; m_pX-> pY-> Z(this); calss X有m_pX,它指向Y类.Calss Y有成员函数Z.在这个例子中,"this"和指针指向X类或Y类?

In  m_pX->pY->Z ( this ); calss X has m_pX which points to class Y. Calss Y has member funtion Z. In this example, "this" pointer points to class X or class Y ?

谢谢

推荐答案

在12/7/2016 10:39 PM,HenryJang写道:

On 12/7/2016 10:39 PM, HenryJang wrote:


对此指针的使用感到困惑..



In  m_pX-> pY-> Z(this); calss X有m_pX,它指向Y类.Calss Y有成员函数Z.在这个例子中,"this"和指针指向类X或类Y?

Confused about the usage of this pointer..

In  m_pX->pY->Z ( this ); calss X has m_pX which points to class Y. Calss Y has member funtion Z. In this example, "this" pointer points to class X or class Y ?

此代码位于某个类的成员函数体中。 "这"是指向该类实例的指针 - 调用该成员函数的实例。

This code is in the body of a member function of some class. "this" is the pointer to an instance of that class - the instance on which that member function is called.

换句话说,你有类似

void SomeClass::SomeMethod() {
    DoSomethingWith(this);
}

此处,"this"是SomeClass *。

Here, "this" is SomeClass*.


这篇关于这个指针在C ++中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆