fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct A{
  5. virtual void foo() = 0;
  6. };
  7.  
  8. struct B:A{
  9. void foo() { cout<< "A" << endl;};
  10. };
  11.  
  12. struct C:A{
  13. void foo() { cout<< "C" << endl;};
  14. };
  15.  
  16. template <class T>
  17. struct enc{
  18. T in; // should be private, I'm just lazy :)
  19. A &a;
  20. int x;
  21. enc(): in(T()), a(in), x(0) {
  22. }
  23.  
  24. };
  25. int main() {
  26. enc<C> c;
  27. c.a.foo();
  28. enc<B> b;
  29. b.a.foo();
  30. return 0;
  31. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
C
A