#include <iostream>
using namespace std;
template <class T> class MyClass {
T x, y;
public:
MyClass(T a, T b) {
x = a;
y = b;
}
T div() { return x/y; }
};
int main()
{
MyClass<double> d_ob(10.0, 3.0 ); // doubles.
cout << "double division: " << d_ob.div() << "\n";
MyClass<int> i_ob(10, 3); // for ints.
cout << "integer division: " << i_ob.div() << "\n";
return 0;
}
|