【发布时间】:2016-07-18 19:39:46
【问题描述】:
我测试了一些c++14的新函数,我想知道为什么这些指针没有相同的地址
#include <iostream>
#include <memory>
class Test
{
public :
Test(){std::cout << "Constructor" << std::endl;}
Test(int val){value = val;}
~Test(){std::cout << "Destructor" << std::endl;}
private :
unsigned int value;
};
int main(int argc, char *argv[])
{
std::unique_ptr<Test> ptr(new Test(45));
std::cout << &ptr << std::endl;
std::unique_ptr<Test> ptr2 (std::move(ptr));
std::cout << &ptr2 << std::endl;
return 0;
}
Output :
0xffffcbb0
0xffffcba0 //Why it's not the same as previous
Destructor
谢谢 :) 祝你有美好的一天
【问题讨论】:
-
FWIW,这是 C++11 代码。那里没有特定于 C++14 的内容。
-
你永远不会移动变量的地址。你改变他们的价值观。
标签: c++ c++11 pointers smart-pointers