day 6 c++

day 6 c++_第1张图片

 

#include 

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;
}

day 6 c++_第2张图片


#include 

using namespace std;
template  
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="<

 

你可能感兴趣的:(c++,算法,开发语言)