什么是& **这完全返回? [英] What does &**this return exactly?
问题描述
这是一个指向调用对象的指针(它返回r值)。
*这是一个指向调用对象的指针该地址的值)。
**这是一个指向调用对象(???)的指针的指针。
& ***这是对调用对象(???)的指针指针的引用。
std :: vector< int> :: iterator i = vector1.begin();
i是指向其自己的r值的指针(返回自己的值)。
* i是向量中包含的对象的r值的指针(返回指向& value的值)。
** i是指向包含在向量(???)中的对象的r值的指针。
我真的很困惑。
下面是一个示例代码,其中我们找到表达式& ** this:
code> class _Iter
{
private:
ListElem * pCurr;
const List * pList;
public:
_Iter(ListElem * pCurr,const List * list)
:pCurr_(pCurr),pList(list)
{}
b $ b T& operator *(){return pCurr _-> data; }
T * operator->(){return& ** this; }
};
$ c>是指向当前对象的指针。
* this
是对当前对象的引用,即此
已取消引用。
如果从<$ c返回的对象的值超过了 示例: 输出示例: this is a pointer to the calling object (it returns the r-value). *this is a pointer to the pointer of the calling object (it returns the value of the address). **this is a pointer to the pointer of the pointer of the calling object (???). &***this is a reference to the pointer of the pointer of the pointer of the calling object (???). i is the pointer to its own r-value (returns its own value). *i is the pointer of a r-value of an object contained in a vector (returns the value pointed in &value). **i is the pointer to the pointer of a r-value of an object contained in a vector (???). I am really confused. Here's a sample code where we find the expression &**this:
If the object returned from Example: Sample output:
这篇关于什么是& **这完全返回?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ c> **此
具有重载的运算符和()
函数,然后& ** this
计算返回值(** this).operator&()
。否则,& **这个
是指向重载的一元运算符*
当前对象。
#include< iostream&
struct A
{
int b;
int a;
int&运算符*(){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;
}
地址aa:0x7fffbc200754
地址aa:0x7fffbc200754
地址aa:0x7fffbc200754
std::vector<int>:: iterator i = vector1.begin();
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
is a pointer to the current object.*this
is a reference to the current object, i.e. this
dereferenced.**this
is the returned value of the overloaded unary operator*
function called on the current object.**this
has an overloaded operator&()
function, then &**this
evaluates to the returned value of (**this).operator&()
. Otherwise, &**this
is the pointer to the returned value of the overloaded unary operator*
function called on the current object.#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