小编Ran*_*Hao的帖子

是否可以获取“ this”指针的地址?

我读到这this是一个右值,我们无法通过应用来获取其地址&this

在我的代码中,我尝试使用的引用绑定this。我想知道哪种地址可以给this?还是都错了?

到底是this什么?左值,右值,关键字还是其他?

void MyString::test_this() const{
    std::cout << "this: " << this << std::endl;
    const MyString * const& this_ref = this;
    std::cout << "thie_ref: " << &this_ref << std::endl;
    const MyString * const&& this_right = this;
    std::cout << "thie_right: " << &this_right << std::endl;
}

//this: 00CFFC14
//thie_ref: 00CFFB14
//thie_right: 00CFFAFC
Run Code Online (Sandbox Code Playgroud)

c++ reference this rvalue rvalue-reference

16
推荐指数
3
解决办法
1083
查看次数

标签 统计

c++ ×1

reference ×1

rvalue ×1

rvalue-reference ×1

this ×1