#include <iostream>
using namespace std;
class Animal
{
public:
Animal()
{
cout << "训练员的无参构造" << endl;
}
virtual void perform()
{
}
};
class Tiger:public Animal
{
string tezheng;
string biaoyan;
public:
Tiger()
{
cout << "老虎的无参构造" << endl;
}
Tiger(string tezheng,string biaoyan):tezheng(tezheng),biaoyan(biaoyan)
{
cout << "老虎的有参构造" << endl;
}
void perform()
{
cout << tezheng << endl;
cout << biaoyan << endl;
}
};
int main()
{
Animal *p= new Tiger("高大凶猛的百兽之王","猛虎过江");
p->perform();
delete p;
cout << "Hello World!" << endl;
return 0;
}
#include <iostream>
using namespace std;
template <typename T>
void fun(T &a,T &b)
{
T t;
t=a;
a=b;
b=t;
}
int main()
{
char a='a';
char b='b';
fun(a,b);
cout << "a="<<a<< " " << "b="<<b << endl;
int a1=10;
int b1=20;
fun(a,b);
cout << "a1="<< a<<" " << "b1="<<b << endl;
return 0;
}