c++抽象类概念

#include "Englishman.h"
#include "Chinese.h"


int main(int argc, char **argv)
{
Englishman e;
Chinese c;


e.setName("Bill");
c.setName("zhangsan");


e.eating();
c.eating();

return 0;
}


#ifndef _CHINESE_H
#define _CHINESE_H


#include <iostream>
#include <string.h>
#include <unistd.h>


#include "Human.h"


using namespace std;


class Chinese : public Human{
public:
void eating(void);
void wearing(void);
void driving(void);
~Chinese();
};


#endif


#include "Englishman.h"




void Englishman::eating(void) 

cout<<"use knife to eat"<<endl; 
}


void Englishman::wearing(void) 
{
cout<<"wear english style"<<endl; 
}


void Englishman::driving(void) 
{
cout<<"drive english car"<<endl; 
}


Englishman::~Englishman() 

cout<<"~Englishman()"<<endl; 
}


#ifndef _HUMAN_H
#define _HUMAN_H


#include <iostream>
#include <string.h>
#include <unistd.h>


using namespace std;


class Human {
private:
char *name;


public:
void setName(char *name);
char *getName(void);

};


#endif


#include "Chinese.h"




void Chinese::eating(void) 

cout<<"use chopsticks to eat"<<endl; 
}


void Chinese::wearing(void) 
{
cout<<"wear chinese style"<<endl; 
}


void Chinese::driving(void) 
{
cout<<"drive chinese car"<<endl; 
}


Chinese::~Chinese() 

cout<<"~Chinese()"<<endl; 
}


#include "Human.h"


void Human::setName(char *name) 
{
this->name = name;
}


char *Human::getName(void) 
{
return this->name;
}
#ifndef _ENGLISHMAN_H
#define _ENGLISHMAN_H


#include <iostream>
#include <string.h>
#include <unistd.h>


#include "Human.h"


using namespace std;


class Englishman : public Human {
public:
void eating(void);
void wearing(void);
void driving(void);
~Englishman();
};


#endif




Human: main.o Chinese.o Englishman.o Human.o
g++ -o $@ $^


%.o : %.cpp
g++ -c -o $@ $<


clean:
rm -f *.o Human
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值