小编Ada*_*vet的帖子

C++为什么它不是相同的地址(指针)

我测试了一些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;
}  
Run Code Online (Sandbox Code Playgroud)


Output : 
    0xffffcbb0
    0xffffcba0 //Why it's not the same as previous 
    Destructor
Run Code Online (Sandbox Code Playgroud)

谢谢你,有一个美好的一天

c++ pointers smart-pointers c++11

2
推荐指数
1
解决办法
178
查看次数

标签 统计

c++ ×1

c++11 ×1

pointers ×1

smart-pointers ×1