LINUX.ORG.RU

История изменений

Исправление Twissel, (текущая версия) :

#include <iostream>
#include <memory>
using namespace std;
 
int main(int argc, char **argv)
{
    int *i = new int;
    auto_ptr<int> x(i);
    auto_ptr<int> y;
 
    y = x;
 
    cout << x.get() << endl; // Print NULL
    cout << y.get() << endl; // Print non-NULL address i
 
    return 0;

Вроде этого примера из Вики, да?

P.S. Хотя цитата из той же Википедии:

Because of its copy semantics, auto_ptr may not be used in STL containers that may perform element copies in their operations.

Исходная версия Twissel, :

#include <iostream>
#include <memory>
using namespace std;
 
int main(int argc, char **argv)
{
    int *i = new int;
    auto_ptr<int> x(i);
    auto_ptr<int> y;
 
    y = x;
 
    cout << x.get() << endl; // Print NULL
    cout << y.get() << endl; // Print non-NULL address i
 
    return 0;

Вроде этого примера из Вики, да?