//
// main.cpp
// project
//
// Created by 徐伟 on 6/5/16.
// Copyright © 2016 fizz_i. All rights reserved.
//
#include <iostream>
using namespace std;
template<class T1,class T2>
class Test{
public:
Test(T1 date1,T2 date2);
Test(Test &a);
void SetData1(T1 val);
void SetData2(T2 val);
T1 GetData1();
T2 GetData2();
private:
T1 data1;
T2 data2;
};
template<class T1,class T2>Test<T1,T2>::Test(T1 data1,T2 data2):data1(data1),data2(data2){}
template<class T1,class T2>Test<T1,T2>::Test(Test &a)
{
data1=a.data1;
data2=a.data2;
}
template<class T1,class T2>inline void Test<T1, T2>::SetData1(T1 val)
{
data1=val;
}
template<class T1,class T2>inline void Test<T1, T2>::SetData2(T2 val)
{
data2=val;
}
template<class T1,class T2>inline T1 Test<T1,T2>::GetData1()
{
return data1;
}
template<class T1,class T2>inline T2 Test<T1,T2>::GetData2()
{
return data2;
}
int main()
{
Test<int, double>a(5,4.2),b(a);
cout<<a.GetData1()<<" "<<a.GetData2()<<endl;
a.SetData1(6);
a.SetData2(5.6);
cout<<a.GetData1()<<" "<<a.GetData2()<<endl;
cout<<b.GetData1()<<" "<<b.GetData2()<<endl;
return 0;
}
两个成员的类模板
最新推荐文章于 2022-03-29 12:00:30 发布