![]()
/*★ template Class 前田 稔 ★*/
#include <iostream>
using namespace std;
template <class Type> class Point
{ public:
Type X;
Type Y;
Point();
Point(Type x, Type y);
void disp();
};
|
//Constructor
template <class Type> Point<Type>::Point()
{ X= 0;
Y= 0;
}
template <class Type> Point<Type>::Point(Type x, Type y)
{ X= x;
Y= y;
}
//disp() 関数
template <class Type> void Point<Type>::disp()
{
cout << "X=" << X << " Y=" << Y << endl;
}
|
void main()
{
Point<int> *ipt;
Point<float> *fpt;
ipt= new Point<int>(200,100);
ipt->disp();
fpt= new Point<float>(123.4f,56.7f);
fpt->disp();
delete ipt;
delete fpt;
}
|
![]()