fork download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. class Person
  5. {
  6. public:
  7. Person(const std::string& name):
  8. name(name) { }
  9.  
  10. ~Person() { std::cout << "Destroyed" << std::endl; }
  11.  
  12. std::string name;
  13. };
  14.  
  15. typedef struct _container
  16. {
  17. std::unique_ptr<Person> ptr;
  18. }CONTAINER;
  19.  
  20. void func()
  21. {
  22. CONTAINER* c = static_cast<CONTAINER*>(malloc(sizeof(CONTAINER)));
  23. std::unique_ptr<Person> p(new Person("FooBar"));
  24. c->ptr = std::move(p);
  25. std::cout << c->ptr->name << std::endl;
  26. delete c;
  27. }
  28.  
  29.  
  30. int main()
  31. {
  32. func();
  33. getchar();
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
FooBar
Destroyed