fork download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. struct Interf {
  8. virtual void test() {cout << "I am Interf" << endl;}
  9. };
  10.  
  11. struct A {
  12. A(std::unique_ptr<Interf> e) : _e(std::move(e)) {}
  13.  
  14. std::unique_ptr<Interf> _e;
  15.  
  16. void test() {_e->test();}
  17.  
  18. };
  19.  
  20.  
  21.  
  22. struct Impl : public Interf {
  23. void test() {cout << "I am Impl;" << endl;}
  24. };
  25.  
  26.  
  27.  
  28. int main()
  29. {
  30. std::unique_ptr<Interf> b(new Impl);
  31.  
  32. A a(std::move(b));
  33.  
  34. a.test();
  35.  
  36.  
  37. cout << "fine!" << endl;
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
I am Impl;
fine!