illegal use of type 'void'怎么改正
#include<iostream>using namespace std;
class Base1{
public:
virtual void display() const=0;
virtual void food() const=0;
};
class Base2:public Base1{
public:
void display() const;
void food() const;
};
void Base2::display() const{
cout<<"第一层的是动物"<<endl;
}
void Base2:food() const{
}
class Base3:public Base2{
public:
void display() const;
void food() const;
};
void Base3::display() const{
cout<<"第二层的有动物下的猴子,猫科和鸟"<<endl;
}
void Base3::food() const{
cout<<"猴子一般都是吃水果的"<<endl;
}
class Base4:public Base3{
public:
void display() const;
void food() const;
};
void Base4::display() const{
cout<<"第三层中有猫科之下的狮子和老虎,鸟之下的麻雀"<<endl;
}
void Base4::food() const{
cout<<"狮子和老虎都是吃肉的,而麻雀是吃素的"<<endl;
}
void fun(Base1 *ptr){
ptr->display();
}
void fun1(Base1 *p){
p->food();
}
int main(){
Base2 base2;
Base3 base3;
Base4 base4;
fun(&base2);
fun1(&base2);
fun(&base3);
fun1(&base3);
fun(&base4);
fun1(&base4);
return 0;
}