类标识符永远不起作用?

时间:2013-12-24 00:40:56

标签: c++ class object aggregation abstract-data-type

我正在创建一个使用FeetInches类的RoomDimension类,但每当我在RoomDimension中使用FeetInches时,我都会收到大量错误消息,包括:

错误C2146:语法错误:缺少';'在标识符“长度”之前

错误C4430:缺少类型说明符 - 假设为int。注意:C ++不支持default-int

以下是课程:

class FeetInches
{
private:
   int feet;        // To hold a number of feet
   int inches;      // To hold a number of inches

public:
   // Constructor
    FeetInches(int f = 0, int i = 0)
        { feet = f;
          inches = i; }

   // Mutator functions
    void setFeet(int f)
        { feet = f; }

    void setInches(int i)
        { inches = i; }

   // Accessor functions
    int getFeet() const
        { return feet; }

    int getInches() const
        { return inches; }

};

class RoomDimension
{
private:

    FeetInches length;
    FeetInches width;

public:

    // constructors
    RoomDimension(void);

    // getter functions
    FeetInches getLength(void) const
    { return length; }

    FeetInches getWidth(void) const
    { return width; }

    // setter functions
    void setLength(FeetInches l)
    { length = l; }

    void setWidth(FeetInches w)
    { width = w; }

};

我做错了什么?

1 个答案:

答案 0 :(得分:1)

除了RoomDimension的构造函数没有实现之外,我没有看到任何问题。