fork(5) download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <memory>
  4. using namespace std;
  5. struct B{
  6. };
  7. struct D : B{
  8. string s;
  9. D(string s): s(s){}
  10. };
  11. int main() {
  12. vector<unique_ptr<B>> vec;
  13. unique_ptr<D> derivedObject( new D("Ram") );
  14. cout << derivedObject.get() << endl;
  15. vec.push_back(make_unique<D>("Ram"));
  16. vec.push_back(std::move(derivedObject));
  17. cout << derivedObject.get() << endl;
  18. return 0;
  19. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
0x9c33a28
0x9c33a28