我读到这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)