fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <typeinfo>
  4. using namespace std;
  5.  
  6. template<typename T>
  7. class fooBase
  8. {
  9. public:
  10. void on1msTimer() { cout << "on1msTimer for "<< typeid(T).name() <<endl; }
  11. virtual ~fooBase() {}; // for using type information
  12. };
  13.  
  14. class foo
  15. : public fooBase<uint8_t>
  16. , public fooBase<uint16_t>
  17. , public fooBase<float>
  18. {
  19. public:
  20. void onTimer()
  21. {
  22. fooBase<float>::on1msTimer();
  23. fooBase<uint8_t>::on1msTimer();
  24. fooBase<uint16_t>::on1msTimer();
  25. }
  26. using fooBase<float>::on1msTimer; // to make one of the 3 function the one for foo
  27. ~foo() {} // required because of virtual destructor in base class
  28. };
  29.  
  30.  
  31. int main() {
  32. foo test;
  33. cout << "Timer:" <<endl;
  34. test.onTimer();
  35. cout << "Explicit call of one of the base timer:"<<endl;
  36. test.fooBase<float>::on1msTimer();
  37. cout << "Call of selected base timer made visible in foo:"<<endl;
  38. test.on1msTimer();
  39. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
Timer:
on1msTimer for f
on1msTimer for h
on1msTimer for t
Explicit call of one of the base timer:
on1msTimer for f
Call of selected base timer made visible in foo:
on1msTimer for f