fork download
  1. #include <iostream>
  2. using namespace std;
  3. using std::cout;
  4. using std::endl;
  5. class Container1
  6. {
  7. public:
  8. Container1() :name ("Cont1")
  9. {};
  10. string name;
  11. // implementation here
  12. };
  13.  
  14. class Container2
  15. {
  16. public:
  17. Container2() :name ("Cont2") {};
  18. string name;
  19. // implementation here
  20. };
  21.  
  22. template<typename ContainerType>
  23. void my_function(ContainerType const& container)
  24. {
  25.  
  26. cout << "my_function called: " << container.name << std::endl;
  27. }
  28. int main(int argc, char* argv[])
  29. {
  30. Container1 cont1;
  31. Container2 cont2;
  32. my_function(cont1);
  33. my_function(cont2);
  34.  
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
my_function called: Cont1
my_function called: Cont2