Warning message 'will be initialized [-Wreorder]'
Solved
General and Desktop
-
Warning message
room.cpp:1: In file included from ..\room.cpp:1:0: room.h:-1: In constructor 'Room::Room(const QString&, const QString&, const QString&, int, QWidget*)': room.h:28: warning: 'Room::roomId' will be initialized after [-Wreorder] const QString roomId; ^ room.h:26: warning: 'QString Room::sleepPrice' [-Wreorder] QString sleepPrice; ^ room.cpp:12: warning: when initialized here [-Wreorder] Room::Room(const QString &_roomId , const QString &_takePrice , ^
My source generates the above warning message.
It works well.
Why is that message coming up?
How do I resolve it?room.h file
#ifndef ROOMBUTTON_H #define ROOMBUTTON_H #include <QPushButton> class Room : public QPushButton { Q_OBJECT public: explicit Room(const QString &_roomId , QWidget *parent = nullptr); explicit Room(const QString &_roomId , const QString &_takePrice , const QString &_sleepPrice , int _sellType , QWidget *parent = nullptr); static int count; enum{ emptyRoom = 0, usingRoom = 1, cleaningRoom =2 }; enum{ take_sleepRoom = 0, takeRoom = 1, sleepRoom = 2 }; private: void setWidgetProperties(); QString sleepPrice; QString takePrice; const QString roomId; int sellType; private slots: void roomClicked(); signals: void getId(const QString &num); void getSleepPrice(QString &price); void getTakePrice(QString &price); }; #endif // ROOMBUTTON_H
room.cpp file
#include "room.h" #include <QDebug> Room::Room(const QString &_roomId,QWidget *parent) : QPushButton(parent) , roomId(_roomId) { setWidgetProperties(); ++count; } Room::Room(const QString &_roomId , const QString &_takePrice , const QString &_sleepPrice , int _sellType , QWidget *parent): QPushButton (parent), roomId(_roomId), sleepPrice(_sleepPrice), takePrice (_takePrice), sellType (_sellType) { setWidgetProperties(); ++count; } int Room::count = -1; void Room::setWidgetProperties() { this->setText(roomId); QSizePolicy sizePolicy2(QSizePolicy::Minimum, QSizePolicy::Preferred); this->setSizePolicy(sizePolicy2); QFont font = this->font(); font.setPointSize(24); this->setFont(font); connect(this,&QPushButton::clicked,this,&Room::roomClicked); } // SLOT void Room::roomClicked() { emit getId(roomId); emit getSleepPrice(sleepPrice); emit getTakePrice(takePrice); }
I thank you in advance for your advice.