编译器警告-fpermissive

时间:2017-05-26 10:12:20

标签: c++ qt compiler-errors compiler-warnings

在我的代码中,我预定了一些类,因为它们之间的引用是这样的:

class Light;
class Room;

class Light : public AbstractModel {
    int mId;
    QString mName;
    QString mAddress;
    bool mIsOn;
    LightType mType;
    QString mColor;

    int mRoomId;
    Room * mRoom;
public:
    Light();
    Light(const QString& name, const QString& address, int roomId, bool isOn, LightType type, const QString& color);
    virtual ~Light();

    const QString& Name() { return mName; }
    const QString& Address() { return mAddress; }
    int RoomId() { return mRoomId; }
    bool IsOn() { return mIsOn; }
    LightType Type() { return mType; }
    const QString& Color() { return mColor; }
    Room * Room();
    QList<Rule *> Rules();

    void setName(const QString& name);
    void setAddress(const QString& address);
    void setIsOn(bool isOn);
    void setColor(const QString& color);
    void setType(LightType type);
    void setRoomId(int id);

    static bool CreateIfNotExists();
    static bool Drop();

    static QList<Light *> GetAllLights();
    static Light * GetLight(int id);
    static Light * GetLightByAddress(const QString& address);
    static QList<Light *> GetLightsByRoom(int roomId);

    bool Insert();
    bool Update();
    bool Remove();
};

class Room : public AbstractModel {
    int mId;
    QString mName;
    QList<Light *> mLights;
public:
    Room();
    Room(const QString& name);
    virtual ~Room();

    const QString& Name() { return mName; }
    const QList<Light *> Lights();

    void setName(const QString& name);

    static bool CreateIfNotExists();
    static bool Drop();

    static Room * GetRoom(int id);
    static QList<Room *> GetAllRooms();

    bool Insert();
    bool Update();
    bool Remove();
};

在Windows上它编译得很好但是在ubuntu上它给了我一个错误,类Light中的Room声明改变了Room的含义。我用-fpermissive标志修复了它,现在它只是一个警告。

为什么在ubuntu中出现问题?

现在警告

../HomeControlApi/dbmodels.h:60:17: warning: declaration of ‘DbModels::Room* DbModels::Light::Room()’ [-fpermissive]
 Room * Room();
             ^
../HomeControlApi/dbmodels.h:29:7: warning: changes meaning of ‘Room’ from ‘class DbModels::Room’ [-fpermissive]
 class Room;

0 个答案:

没有答案