fork download
  1. #include <iostream>
  2.  
  3. template <class Ty1, class Ty2>
  4. class Pair
  5. {
  6. public:
  7. typedef Ty1 first_type;
  8. typedef Ty2 second_type;
  9.  
  10. first_type first;
  11. second_type second;
  12.  
  13. Pair(Ty1, Ty2);
  14. };
  15.  
  16. template <class Ty1, class Ty2>
  17. Pair<Ty1, Ty2>::Pair(Ty1 f, Ty2 s)
  18. : first(f), second(s)
  19. {}
  20.  
  21. template <class Ty1, class Ty2>
  22. Pair<Ty1, Ty2> make_pair(Ty1 f, Ty2 s)
  23. {
  24. return Pair<Ty1, Ty2>(f, s);
  25. }
  26.  
  27. int main()
  28. {
  29. Pair<int, float> foo = make_pair(42, 3.14f);
  30.  
  31. std::cout << "First: " << foo.first << std::endl;
  32. std::cout << "Second: " << foo.second << std::endl;
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
First: 42
Second: 3.14