fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Foo;
  5. class Bar;
  6. class Hoge;
  7.  
  8. class Foo
  9. {
  10. public:
  11. void func() { cout << "func!" << endl; }
  12. Foo(int v) { cout << v << endl; }
  13. Foo() {}
  14. };
  15.  
  16. class Bar : public Foo
  17. {
  18. public:
  19. Bar() {}
  20. Bar(int v) : Foo(v) {}
  21. };
  22.  
  23. class Hoge
  24. {
  25. public:
  26. void func() { cout << "Hoge!" << endl; }
  27. };
  28.  
  29. template <class T>
  30. void call_func(T& t) {
  31. t.func();
  32. }
  33.  
  34. int main() {
  35. Foo foo;
  36. Bar bar;
  37. Hoge hoge;
  38.  
  39. foo.func();
  40. bar.func();
  41. hoge.func();
  42.  
  43. call_func(foo);
  44. call_func(bar);
  45. call_func(hoge);
  46.  
  47. return 0;
  48. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
func!
func!
Hoge!
func!
func!
Hoge!