fork download
  1. #include <iostream>
  2. #include <memory>
  3. using namespace std;
  4.  
  5. struct S
  6. {
  7. S() { cout << "ctor\n"; }
  8. ~S() { cout << "dtor\n"; }
  9. void Foo() { cout << "Foo\n"; }
  10. };
  11.  
  12. std::unique_ptr<S> gS;
  13.  
  14. int main() {
  15. gS = std::make_unique<S>();
  16. cout << "main\n";
  17. {
  18. cout << "scope\n";
  19. std::move(gS)->Foo();
  20. cout << "end scope\n";
  21. }
  22. cout << "end main\n";
  23. return 0;
  24. }
Success #stdin #stdout 0s 4348KB
stdin
Standard input is empty
stdout
ctor
main
scope
Foo
end scope
end main
dtor