Generic Class just for displaying the parameters : Generic Class « Generic « C++






Generic Class just for displaying the parameters

Generic Class just for displaying the parameters
#include <iostream>
#include <fstream>
using namespace std;

template <class CoordType> class MyClass {
  CoordType x, y;
public:
  MyClass(CoordType i, CoordType j) { 
     x = i; 
     y = j; 
  }
  void show() { 
     cout << x << ", " << y << endl; 
  }
};

int main()
{
  MyClass<int> object1(1, 2), object2(3, 4);
 
  object1.show();
  object2.show();

  MyClass<double> object3(0.0, 0.23), object4(10.19, 3.098);

  object3.show();
  object4.show();

  return 0;
}



           
       








Related examples in the same category

1.Generic data types in a class definition.Generic data types in a class definition.
2.Generic Class: constructorGeneric Class: constructor