#include <iostream>
using namespace std;
class Room
{
public:
int length,
width,
number,
Area2;
public:
Room(int l = 600, int w = 1000, int r = 6, int a)
{
length = l;
width = w;
number = r;
Area2 = a;
}
int getArea()
{
return length * width;
}
};
class House
{
public:
int len,
wid;
Room r1;
public:
House(int ll = 20, int ww = 60, int r = 6)
: r1(r)
{
len = ll;
wid = ww;
}
int Room_function()
{
int Area1, Area2, r;
Area1 = Area2 * r;
cout << "total area of the house:" << Area1;
r1.getArea(Area2);
}
};
int main()
{
int l, w, r, a;
Room r3();
a = r3.getArea();
cout << "Area of one Room:" << Area2 << endl;
int l1, w1;
House h1();
h1.r1.getArea(Area2);
h1.Room_function();
system("PAUSE");
return 0;
}
答案 0 :(得分:1)
Room r3();
r3
不是对象,而是返回类型为Room
的函数声明。删除()
。阅读Most Vexing Parse。
答案 1 :(得分:0)
我认为这不是一个有效的构造函数:
Room(int l=600, int w= 1000, int r=6 ,int a)
您最多只能拥有最右侧参数的默认值。
一旦你有l
(最左边的参数)的默认值,你就不能再有没有默认值的参数(例如a
)。
答案 2 :(得分:0)
你在House类中调用了r1.getArea(Area2)。但是Room类没有getArea(int)类型的任何函数;