c++ 多态

//#ifndef _EXRTENDS_H_
//引用出处:http://topic.csdn.net/u/20070123/10/6A1EF284-8EE1-417F-82B0-2E05F207464F.html#r_39020250
#include "stdafx.h"
#define _EXRTENDS_H_ //WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <TlHelp32.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
//#include   <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <list>
#include <sstream>
#include <algorithm>//for_each
#include <vector>

//#include <afxdb.h>
using std::cout;
using std::endl;

namespace extendsNamespace{
typedef struct stuInfoStruct{  //用了typedef 表示stuInfoStruct的另两个名字是stu1,stu2,stu1,stu2就不为变量了
std::string name;
int age;
}stu1,stu2;

struct stu2Struct
{
std::string pwd;//密码
std::string name;//姓名
std::list<std::pair<std::string,float> > socres;
}stu21obj,stu22obj;  //stu21,stu22两个变量

class Animal{
public:
Animal();//构造函数
~Animal();//柝构函数
Animal(const Animal& rhs);//copy构造函数
Animal &operator = (const Animal& rhs);//赋值运算符
Animal* operator&();// 取址运算符 const Empty* operator&() const;
void eat();
private:
std::string name;//学员name
};

/////////////////////////动态/////////////////////////////////////////////////
class Vehicle//父类
{
public:
virtual void run() const = 0;
};

class Car: public Vehicle//car 继承 Vehicle
{
public:
virtual void run() const
{
std::cout << "run a car"<<std::endl;
}
};

class Airplane: public Vehicle
{
public:
virtual void run()const
{
std::cout << "run a airplane"<<std::endl;
}
};

////////////////////////////静态//////////////////////////////////////////////
/*class Vehicle1//父类
{
public:
void run();
};*/
class Car1
{
public:
void run() const
{
std::cout << "静态:run a car"<<std::endl;
}
};

class Airplane1
{
public:
void run() const
{
std::cout << "静态:run a airplane"<<std::endl;
}
};


}

你可能感兴趣的:(C++)