use*_*155 0 c++ move this c++14
1) How this pointer is different from other pointers? As I understand pointers point to the memory in heap. Does that mean objects are always constructed in heap, given that there is pointer to them?
2)Can we steal this pointer in move constructor or move assignment?
How this pointer is different from other pointers?
this is no different from other pointers, except that you cannot change it's value and that it only exists within member functions. It is a reserved keyword.
As I understand pointers point to the memory in heap. Does that mean objects are always constructed in heap, given that there is pointer to them?
不,指针(有效或无效)可以指向“任何地方”。不可以,结构/类可以分配到任何地方。在自动存储(堆栈)上,在免费存储(堆)上,如果平台支持,则在其他位置。
我们可以在移动构造函数或移动分配中窃取此指针吗?
不确定要问的是什么,但是答案很可能不是。
该指针与其他指针有何不同?
该this指针仅存在于非static类成员函数的上下文中。它也是隐式的,它的名称是保留关键字,并且始终是prvalue表达式。否则,它与任何其他指针相同。
据我了解,指针指向堆中的内存。
指针可以指向内存中的任何内容。它不仅限于堆,也不是对象。
我们可以在移动构造函数或移动分配中窃取此指针吗?
this始终是prvalue表达式。为其分配新地址的可能性超过为分配一个新值的可能性5。事实是对象在整个生命周期中都存在于内存中的一个位置。他们的地址永远无法更改,尝试通过为分配新地址来更改地址是不合逻辑的this。从对象移开会将对象具有的值或状态移到其他位置,但是对象本身仍然存在于其先前的地址处。