fork download
  1. #include <iostream>
  2.  
  3. enum class Some_Enum_Class
  4. {
  5. A, B, C
  6. };
  7. struct Base {
  8. void * data;
  9. Base(){}
  10. virtual ~Base(){}
  11. // ...
  12. virtual bool Read(){std::cout << "hello from base" << std::endl;}
  13. };
  14. template <Some_Enum_Class T>
  15. struct Derived : Base {
  16. // T-specific interface to deal with Base::data
  17. bool Read() { std::cout << "hello from Derived" << std::endl; }
  18. };
  19.  
  20.  
  21. int main() {
  22. Derived <Some_Enum_Class::A> * D = new Derived <Some_Enum_Class::A>;
  23. Base * B = (Base*) D;
  24. void* b = (void*) B;
  25. Base * B2 = (Base*) b;
  26. B2->Read();
  27. return 0;
  28. }
Success #stdin #stdout 0s 3272KB
stdin
Standard input is empty
stdout
hello from Derived