c++prime+重虚函数设计

#include <string>
#include <iostream>
using namespace std;


class worker{
public:
int id;
string name;
worker(int id1=0,string name1=" ",float salary1=0.0):id(id1),name(name1),salary(salary1) {}
virtual void get_salary(int id)
{
cout<<salary<<endl;
}
protected:
float salary;
};


class tem: public worker{
public:
tem(int id1=0,string name1=" ",float salary1=0.0,int level1 = 0):worker(id1,name1,salary1),level(level1) {}
void get_salary(int id) =0;
protected:
int level;
};


class worker_d: public tem{
public:
worker_d(int id1=0,string name1=" ",float salary1=0.0,int level1 = 0):tem(id1,name1,salary1,level1){ }
void get_salary(int id)
{
cout<<id<<"   "<<level<< "    "<<salary;  
}

};

#include "worker.h"


int main()
{
worker a(0,"vivi",3000);
worker_d b(1,"cucu",5000,1);
tem c(2,"cucu",5000,1);
a.get_salary(0);
b.get_salary(1);
}

g++ -o main main.cpp

main.cpp: In function ‘int main()’:
main.cpp:7: error: cannot declare variable ‘c’ to be of abstract type ‘tem’
worker.h:18: note:   because the following virtual functions are pure within ‘tem’:  //纯虚函数
worker.h:21: note: virtual void tem::get_salary(int)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值