这是什么 ? [英] What is *this ?

查看:60
本文介绍了这是什么 ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



嗨!我想知道*这是什么。

我在结构和类中看到*这个。我甚至在一个链表中看到*这个*但是我知道几乎没有链接列表,除了使用

以某种方式动态存储数据。一个

我知道的事情*这个东西......它是指针的b $ b。谢谢大家:-)


问候



解决方案

< blockquote> 在************* @ yahoo.com 写道:

嗨!我想知道这是什么。
我在结构和类中看到*。我甚至在链表中看到了这个*但我几乎不知道链接列表,除了用于动态存储数据之外的其他内容。我知道的一件事*这件事......它是一个指针。谢谢大家: - )




int main()

{

int i = 10;


int * p =& i;

* p = 20;


std :: cout<<一世; // 20

}


在* p = 20行上,您要为我指定一个新值。同样的

的事情


C级{};


int main()

{

C c,d;


C * p =& c;

* p = d;

}


因为在成员函数中''this''指向

函数被调用的对象,


void C :: f()

{

* this = something;

}




相同•
void f(C * c)

{

* c =某事;

}

Jonathan


你能不能更多明确这个?我仍然是c ++的新手,我会像

一样来了解更多关于如何使用这个指针的信息。谢谢


** ***********@yahoo.com 写道:

你能更加明确吗?我还是c ++的新手,我想
更多地了解如何使用这个指针。谢谢




请引用您要回复的消息。


此指针指向您调用的对象会员

功能。我们通常说它是一个隐式参数,虽然它不是必然以这种方式实现的。


class C

{

int i;


public:

void f()

{

i = 10;

}

};


可以被认为是(并且通常被实现为)


class C

{

int i;


public:

void f(C * const this)

{

this-> i;

}

};


所以这个指针是一个普通的指针,虽然它不能被指定为

指向别处。

乔纳森



Hi! I would like to know what *this is .
I see *this in structs and classes. I even
saw *this in a linked list but I know almost
nothing of a linked list except being used
to dynamically store data somehow. One
thing I do know about *this thing ... It''s
a pointer. Thanks people :-)

Regards
Me

解决方案

in*************@yahoo.com wrote:

Hi! I would like to know what *this is .
I see *this in structs and classes. I even
saw *this in a linked list but I know almost
nothing of a linked list except being used
to dynamically store data somehow. One
thing I do know about *this thing ... It''s
a pointer. Thanks people :-)



int main()
{
int i = 10;

int *p = &i;
*p = 20;

std::cout << i; // 20
}

On the line "*p = 20", you are assigning a new value to ''i''. The same
thing for

class C {};

int main()
{
C c, d;

C *p = &c;
*p = d;
}

And since in a member function ''this'' points to the object on which the
function was called,

void C::f()
{
*this = something;
}

is the same thing as

void f(C *c)
{
*c = something;
}
Jonathan


Can you be more explicit with this ? I''m still new to c++ and I would
like
to know more on how the this pointer can be used. thanks


in*************@yahoo.com wrote:

Can you be more explicit with this ? I''m still new to c++ and I would
like
to know more on how the this pointer can be used. thanks



Please quote the message you are answering to.

The this pointer points to the object on which you called the member
function. We usually say it is an implicit parameter, though it is not
necessarily implemented this way.

class C
{
int i;

public:
void f()
{
i = 10;
}
};

can be thought as (and is usually implemented as)

class C
{
int i;

public:
void f(C * const this)
{
this->i;
}
};

So the this pointer is an ordinary pointer, although it cannot be made
to point elsewhere.
Jonathan


这篇关于这是什么 ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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