fork download
  1. #include <iostream>
  2.  
  3.  
  4. template<typename, int Value>
  5. struct parent {
  6.  
  7. void foo() const {
  8. std::clog << "parent: " << Value << std::endl;
  9. }
  10. };
  11.  
  12. template<typename, int>
  13. struct child;
  14.  
  15. template<int Value>
  16. struct child<int, Value> : parent<int, Value> {
  17.  
  18. void bar() const {
  19. this->foo();
  20. std::clog << "child: int, " << Value << std::endl;
  21. }
  22. };
  23.  
  24. template<int Value>
  25. struct child<char, Value> : parent<char, Value> {
  26.  
  27. void bar() const {
  28. this->foo();
  29. std::clog << "child: char, " << Value << std::endl;
  30. }
  31. };
  32.  
  33.  
  34. int main() {
  35. child<int, 1>().bar();
  36. child<char, 2>().bar();
  37. }
  38.  
Success #stdin #stdout #stderr 0s 3292KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
parent: 1
child: int, 1
parent: 2
child: char, 2