简单c++
#include <iosteam>
using std::string;
template<typename T1, typename T2>
class test
{
private:
T1 a;
T2 b;
public:
//virtual int getNumber(char c)=0;
test(T1 x, T2 y) //构造函数
{
a=x;
b=y;
}
~test()
{
cout<<"class test destructor function." << endl;
}
void print()//内联函数
{
cout << "a="<<a<<"b="<<b<<endl;
}
}
int main(int argc, char* argv[])
{
test<int,int> obj(5,10);
obj.print();
test<double,int> obj2(5.2,10);
obj2.print();
test<int,int> obj2(5.2,10);
obj2.print();
}

浙公网安备 33010602011771号