<pre name="code" class="cpp">#include <iostream>
using namespace std;
template <typename T>
class TemplateClassTest
{
public:
TemplateClassTest(T& InA, T& InB):a(InA),b(InB){}
T& getA();
T& getB();
private:
T a;
T b;
};
template <typename T>
T& TemplateClassTest <T>::getA()
{
return a;
}
template <typename T>
T& TemplateClassTest <T>::getB()
{
return b;
}
void main()
{
float TestA = 10.1f;
float TestB = 20.34f;
TemplateClassTest<float> Test1(TestA, TestB);
cout<<Test1.getA()<<endl;
cout<<Test1.getB()<<endl;
while(1);
}
摘自 DriverMonkey的專欄