新手C++ 求救(急)

来源:百度知道 编辑:UC知道 时间:2024/06/05 16:34:51
#include<iostream.h>
class building
{
protected:
int foor,room,area;
public:
building(int f,int r,int a)
{foor=f;room=r;area=a;}
};
class house: protected building
{
protected:
int rooms,washroom;
public:
house(int f,int r,int a,int m,int w):building(f, r, a)
{rooms=m;washroom=w;}
void show()
{cout<<"rooms "<<rooms<<endl;
cout<<"washroom "<<washroom<<endl;
cout<<"foor "<<foor<<endl;
cout<<"room "<<room<<endl;
cout<<"area "<<area<<endl;
}
};
class office:protected building
{ protected:
int fire,phone;
public:
office(int f,int r,int a,int fi,int p):building(f, r, a)
{fire=fi;phone=p;}
void show()
{cout<<"fire "<

最后一个类定义后面没加分号!就是main上面那个。再有就是最好把main前面加上int

问题出在派生类上,你是用的protected派生.换成public派生吧.

在最后一个类后面加分号就可以了

#include<iostream.h>
class building
{
protected:
int foor,room,area;
public:
building(int f,int r,int a)
{foor=f;room=r;area=a;}
};
class house: protected building
{
protected:
int rooms,washroom;
public:
house(int f,int r,int a,int m,int w):building(f, r, a)
{rooms=m;washroom=w;}
void show()
{cout<<"rooms "<<rooms<<endl;
cout<<"washroom "<<washroom<<endl;
cout<<"foor "<<foor<<endl;
cout<<"room "<<room<<endl;
cout<<"area "<<area<<endl;
}
};
class office:protected building
{ protected:
int fire,phone;
public:
office(int f,int r,int a,int fi,int p):