什么是& **这完全返回? [英] What does &**this return exactly?

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

问题描述

这是一个指向调用对象的指针(它返回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返回的对象的值超过了 $ 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


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 (???).

std::vector<int>:: iterator i = vector1.begin();

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:

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.

If the object returned from **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.

Example:

#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;
}

Sample output:

Address of a.a: 0x7fffbc200754
Address of a.a: 0x7fffbc200754
Address of a.a: 0x7fffbc200754

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

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