64,636
社区成员
发帖
与我相关
我的任务
分享
class Bird{
public:
int a;
void eat(int m, int n);
}
#include"bird.h"
int update(Bird *b){
int i = 5;
int j = 6;
b.eat(i, j);
return 0;
}
int main(void){
Bird *bbb = new Bird();
update(bbb);
delete bbb;
return 0;
}
class Bird {
public:
void eat(int, int);
}
无需暴露成员,不影响调用。你将Bird编译成一个静态lib文件就不需要提供cpp文件了,相当于隐藏了实现,但头文件也需要的,因为他需要知道你函数的名字、调用方式、参数等才知如何使用
class IBird{
public:
virtual void eat(int m, int n) = 0;
}
class Bird:public IBird
{
public:
int a;
override void eat(int m, int n){
}
}