는 전 C++ 14의 새로운 기능을 테스트하고 나는이 포인터가 같은 주소C++ (포인터)
#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에는 특별한 것이 없습니다. – chris
변수의 주소를 절대로 이동하지 마십시오. 당신은 그들의 가치관을 옮긴다. – xinaiz