#include <iostream>
using namespace std;
class Animal
{
public:
virtual void perform()=0;
virtual ~Animal()
{
cout<<"Animal的析构函数"<<endl;
}
};
class Lion :public Animal
{
public :
void perform()
{
cout<<"狮子,是食肉目猫科豹属于大型猛兽。其身体柔韧、强壮、胸部厚实;有短而坚硬的头骨和下颚,易于捕食猎物"<<endl;
}
~Lion()
{
cout<<"狮子的析构函数"<<endl;
}
};
class Elephant :public Animal
{
public :
void perform()
{
cout<<"大象(拉丁学名:Elephantidae),是长鼻目象科哺乳动物。"<<endl;
}
};
class Monkey :public Animal
{
public :
void perform()
{
cout<<"猴子是灵长目一些动物的俗称。整个灵长目动物因进化等级的差异可分为两大亚目——原猴亚目和类人猿亚目 ,又称为原猴类和猿猴类。"<<endl;
}
};
int main()
{
Lion shizhi;
Elephant daxiang;
Monkey houzhi;
Animal *p=nullptr;
p=&shizhi;
p->perform();
p=&daxiang;
p->perform();
p=&houzhi;
p->perform();
delete p;
return 0;
}
#include <iostream>
using namespace std;
template <typename T>
void Exchange(T &a,T &b)
{
T temp;
temp=a;
a=b;
b=temp;
}
int main()
{
int a=10,b=20;
Exchange(a,b);
cout<<a <<endl<< b<<endl;
return 0;
}