fork(2) download
  1. #include <iostream>
  2. #include <memory>
  3. using namespace std;
  4.  
  5. struct A{
  6. virtual void foo()=0;
  7. };
  8.  
  9. struct B:A{
  10. void foo() { cout<< "A" << endl;};
  11. };
  12.  
  13. struct C:A{
  14. void foo() { cout<< "C" << endl;};
  15. };
  16.  
  17. struct enc{
  18. unique_ptr<A> a;
  19. int x;
  20. enc(unique_ptr<A> p): a(std::move(p)), x(0) {
  21. }
  22.  
  23. };
  24. int main() {
  25. enc c( unique_ptr<A>(new C()) );
  26. c.a->foo();
  27. enc b( unique_ptr<A>(new B()) );
  28. b.a->foo();
  29. return 0;
  30. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
C
A