Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <cstdio>
- #include <memory>
- #include <ctime>
- using namespace std;
- struct A
- {
- int m;
- A(int i) : m(i) { printf("ctor(%d)\n", i); }
- A(A const& o) : m(o.m) { printf("cctor(%d)\n", o.m); }
- A const& operator=(A const& o){ m = o.m; printf("op=(%d)\n", o.m); }
- ~A() { printf("dtor\n"); }
- };
- A foo() { return A( rand() ); }
- auto_ptr<A> make_unique(A&& a) { return auto_ptr<A>(new A(forward<A>(a))); }
- //unique_ptr<A> make_unique(A&& a) { return unique_ptr<A>(new A(forward<A>(a))); }
- int main()
- {
- srand(time(NULL));
- auto_ptr<A> p( new A(foo()) );
- // auto_ptr<A> p( make_unique(foo()) );
- // unique_ptr<A> p( make_unique(foo()) );
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement