这个设计有点怪!

 

#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;

class Base
{
public:
    Base();
    virtual void DisPaly() = 0;

};

Base::Base()
{

}

class ManA :  public Base
{
public:
    ManA();
    ManA(string name,string sex,int old);
    virtual void DisPaly();
    friend class Show;
private:
    string name;
    string sex;
    int old;
};

ManA::ManA(string name,string sex,int old)
:name(name)
,sex(sex)
,old(old)
{

}

void ManA::DisPaly()
{
    cout<<"ManA--name:"<<name<<endl;
    cout<<"ManA--sex:"<<sex<<endl;
    cout<<"ManA--old:"<<old<<endl;
}


class ManB : public Base
{
public:
    ManB();
    ManB(string name);
    virtual void DisPaly();
    friend class Show;
private:
    string name;
   
};

ManB::ManB()
{

}

ManB::ManB(string name)
:name(name)
{

}

void ManB::DisPaly()
{
    cout<<"ManB--name:"<<name<<endl;
}

class Show
{
public:
    void DisPlay(Base &base);
};

void Show::DisPlay(Base &base)
{
    base.DisPaly();
 
}

 

int _tmain(int argc, _TCHAR* argv[])
{
    ManA man("lhy","man",26);
    ManB B("lhy_class_B");
    Show infoShow;
    infoShow.DisPlay(man);
    infoShow.DisPlay(B);

}

你可能感兴趣的:(这个设计有点怪!)