1.
#include <iostream>
using namespace std;
class Animal
{
private:
int id;
public:
Animal(){}
Animal(int id):id(id)
{}
virtual void show()
{
cout << "动物园门牌号:" << id << endl;
}
};
class Houzi:public Animal
{
private:
string name;
public:
Houzi(){}
Houzi(int i,string n):Animal(i),name(n)
{}
void show()
{
cout << "呀呼" << endl;
}
};
class Dog:public Animal
{
private:
string name;
public:
Dog(){}
Dog(int i,string n):Animal(i),name(n)
{}
void show()
{
cout << "叫叫叫" << endl;
}
};
class Kunkun:public Animal
{
private:
string name;
public:
Kunkun(){}
Kunkun(int i ,string n):Animal(i),name(n)
{}
void show()
{
cout << "坤你太美" << endl;
}
};
int main()
{
Houzi h(123,"wzg");
h.show();
Dog d(123,"gswzg");
d.show();
Kunkun k(123,"cxk");
k.show();
return 0;
}
2.
#include <iostream>
using namespace std;
template <typename T>
void fun(T &a,T &b)
{
T t;
t=a;
a=b;
b=t;
}
int main()
{
int a=10;
int b=2;
char c='1',d='2';
fun(a,b);
cout << a << endl;
cout << b << endl;
fun(c,d);
cout << c << endl;
cout << d << endl;
return 0;
}
3