这不是真正的指针吗? [英] this is not a real pointer?

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

问题描述

我正在阅读有关虚拟表的内容.当涉及到指针__vptr时, 据作者说

I am reading something about virtual table. When it comes to pointer __vptr, it is stated that by the author

*this指针实际上是编译器用来解析自引用的函数参数,而*this指针却是真正的指针.因此,它使分配给每个类对象的指针增加一个指针的大小.

Unlike the *this pointer, which is actually a function parameter used by the compiler to resolve self-references, *__vptr is a real pointer. Consequently, it makes each class object allocated bigger by the size of one pointer.

在这里说this实际上是一个函数参数是什么意思?而且this不是真正的指针吗?

What does it mean here by saying this is actually a function parameter? And this is not a real pointer?

推荐答案

两个指针都是真实的,因为它们将其他内容的地址存储在内存中.与"this"指针相反,作者将真实"表示为存储在类内",而不将其传递给成员函数而不存储在对象本身中.本质上,指向__vptr的指针是对象的一部分,而this指针则不是对象的一部分.

Both pointers are real in the sense that they store an address of something else in memory. By "real" the author means "stored within the class", as opposed to this pointer, which is passed to member functions without being stored in the object itself. Essentially, the pointer to __vptr is part of the object, while this pointer is not.

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

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