fork(4) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. //prototype the class and the functions
  5. template<class T> class strange;
  6. template<class T> ostream& operator<< (ostream& osObject, const strange<T>& sObject);
  7.  
  8.  
  9. //begin class
  10. template <class T>
  11. class strange
  12. {
  13. public:
  14. // .... function prototypes go here.
  15. strange(T x,T y);
  16. friend ostream& operator<< <> (ostream& osObject, const strange<T>& sObject);
  17.  
  18. private:
  19. T a;
  20. T b;
  21. };
  22. // .... your function definitions go here
  23. template <class T>
  24. strange<T>::strange(T first, T second){
  25. a = first;
  26. b = second;
  27. }
  28.  
  29. template <class T>
  30. ostream& operator<< (ostream& osObject, const strange<T>& sObject){
  31. osObject << sObject.a << ", " << sObject.b;
  32. return osObject;
  33. }
  34.  
  35.  
  36.  
  37. int main()
  38. {
  39. strange<int> x1(4,6) , x2(12,2) ;
  40. //strange<char> y1('m','n') , y2('m','n') ;
  41. cout << "x1 = " << x1 << endl;
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0.01s 2680KB
stdin
Standard input is empty
stdout
x1 = 4, 6