Skip to main content
1 of 4
JKor
  • 186
  • 1
  • 7

#C++ This behavior is actually specified in the standard (and that's why it was deprecated).

#include<iostream>
#include<memory>
int main()
{
    std::auto_ptr<int> a = new int(0);
    std::cout<<a.get()<<'\n';
    std::auto_ptr<int> b = a;
    std::auto_ptr<<a.get()<<'\n';
}

Output

some address
0

The process that causes this is the same as Abhijit's answer but without requiring a std::move and the same as marinus' answer but using a standard class instead of defining it myself.

JKor
  • 186
  • 1
  • 7