-1
#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;
}
4

3 回答 3

1
Room r3();

r3不是对象,而是返回类型为 的函数声明Room。删除(). 阅读最令人烦恼的解析

于 2013-11-03T12:51:27.083 回答
0

您在 House 类中调用了 r1.getArea(Area2)。但是 Room 类没有任何类型的函数 getArea(int);

于 2013-11-03T12:56:28.610 回答
0

我不认为这是一个有效的构造函数:

Room(int l=600, int w= 1000, int r=6 ,int a)

您只能为最右边的参数设置默认值。

一旦有了l(最左边的参数)的默认值,就不能再有没有默认值的参数(例如a)。

于 2013-11-03T12:54:01.660 回答