Generic Class: constructor : Generic Class « Generic « C++






Generic Class: constructor

Generic Class: constructor
#include <iostream>
using namespace std;

template <class X> class input {
  X data;
public:
  input(char *s, X min, X max);
  
};

template <class X> 
input<X>::input(char *s, X min, X max)
{
  do {
    cout << s << ": ";
    cin >> data;
  } while( data < min || data > max);
}

int main()
{
  input<int> i("enter int", 0, 10);
  input<char> c("enter char", 'A', 'Z');

  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 just for displaying the parametersGeneric Class just for displaying the parameters