fork download
  1. /*****************************************************************
  2. Name :
  3. Date : 2017/05/12
  4. By : CharlotteHonG
  5. Final: 2017/05/12
  6. *****************************************************************/
  7. #include <iostream>
  8. using namespace std;
  9.  
  10. template <class T>
  11. struct Base{
  12. Base(int i=0): num(i){}
  13. void interface(){
  14. static_cast<T*>(this)->implementation();
  15. }
  16. // static void static_func(){
  17. // T::static_sub_func();
  18. // }
  19. int num;
  20. };
  21.  
  22. struct Derived : Base<Derived>{
  23. Derived(int i=0):Base<Derived>(i){}
  24. void implementation(){
  25. cout << "num=" << num << endl;
  26. }
  27. // static void static_sub_func();
  28. };
  29.  
  30. int main(int argc, char const *argv[]){
  31. Base<Derived>* p = new Derived(10);
  32. p->interface();
  33. return 0;
  34. }
Success #stdin #stdout 0s 15224KB
stdin
Standard input is empty
stdout
num=10