- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
这是一个指向调用对象的指针(它返回右值)。
*这是一个指向调用对象指针的指针(它返回地址的值)。
**这是一个指向调用对象(???)的指针的指针。
&***这是对调用对象指针(???)的指针的引用。
std::vector<int>:: iterator i = vector1.begin();
i 是指向它自己的右值的指针(返回它自己的值)。
*i 是 vector 中包含的对象的右值指针(返回 &value 中指向的值)。
**i 是指向 vector 中包含的对象的右值指针的指针 (???)。
我真的很困惑。
这是一个示例代码,我们在其中找到表达式 &**this:
class _Iter
{
private:
ListElem *pCurr;
const List *pList;
public:
_Iter(ListElem *pCurr, const List *list)
: pCurr_(pCurr), pList(list)
{}
T& operator*() { return pCurr_->data; }
T* operator->() { return &**this; }
};
最佳答案
this
是指向当前对象的指针。
*this
是对当前对象的引用,即 this
取消引用。
**this
是在当前对象上调用的重载一元 operator*
函数的返回值。
如果从 **this
返回的对象有一个重载的 operator&()
函数,那么 &**this
计算返回值(**this).operator&()
的。否则,&**this
是指向在当前对象上调用的重载一元 operator*
函数的返回值的指针。
例子:
#include <iostream>
struct A
{
int b;
int a;
int& operator*() {return a;}
int* test()
{
return &**this;
}
};
int main()
{
A a;
std::cout << "Address of a.a: " << a.test() << std::endl;
std::cout << "Address of a.a: " << &(*a) << std::endl;
std::cout << "Address of a.a: " << &(a.a) << std::endl;
return 0;
}
示例输出:
Address of a.a: 0x7fffbc200754
Address of a.a: 0x7fffbc200754
Address of a.a: 0x7fffbc200754
关于c++ - &**this 究竟返回了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22368300/
Feel free to skip straight to TL/DR if you're not interested in details of the question 简短的序言: 我最近决定
我一直在阅读 A Tour of Go学习Go-Lang到目前为止一切顺利。 我目前在 Struct Fields类(class),这是右侧的示例代码: package main import "fm
Last time I got confused顺便说一下PowerShell急切地展开集合,基思总结了它的启发式如下: Putting the results (an array) within a
我是一名优秀的程序员,十分优秀!