fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class object
  5. {
  6. public:
  7. void set_tag(int t){
  8. tag = t;
  9. }
  10.  
  11. int get_tag(){
  12. return tag;
  13. }
  14.  
  15. private:
  16. int tag;
  17. };
  18.  
  19. template<typename T>
  20. class printer
  21. {
  22. public:
  23. void print()
  24. {
  25. T* obj = static_cast<T*>(this);
  26. std::cout << obj->get_tag() << std::endl;
  27. }
  28. };
  29.  
  30. class test : public object, public printer<test>
  31. {
  32. };
  33.  
  34. int main()
  35. {
  36. test t;
  37. t.set_tag(5);
  38. t.print();
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
5