템플릿을 이용한 클래스 작성하기 ^^
#include <iostream>
using namespace std;
template <typename t>
class posvalue
{
private:
int x,y;
t value;
public:
posvalue(int ax, int ay, t av) : x(ax),y(ay),value(av) { }
t get();
void set(t a);
void outvalue();
};
template <typename t>
void posvalue<t>::set(t a)
{
value = a;
}
template <typename t>
t posvalue<t>::get()
{
return value;
}
template <typename t>
void posvalue<t>::outvalue()
{
cout<<"[x , y]:"<< x <<" ,"<< y <<" "<<"[value]: "<< value <<endl;
}
int main(void)
{
int i;
double d;
char c;
posvalue<int> iv(1,1,2);
posvalue<char> cv(5,1,'c');
posvalue<double> dv(30,2,3.14);
iv.outvalue();
cv.outvalue();
dv.outvalue();
cout<<"\n추가 함수 get(), set() "<<endl;
i = iv.get();
iv.set(5);
c= cv.get();
cv.set('s');
d= dv.get();
dv.set(5.12);
cout<<endl;
cout<<i<<" "<<c<<" "<<d<<endl;
cout<<"--------수정전-------"<<endl<<endl;
iv.outvalue();
cv.outvalue();
dv.outvalue();
}