Re: expected unqualified-id before public
Hi all.
I am getting this error when compiling. But the compiler does not tell me where the error is. I am able to compile the files outside Qt creator.
It seems that the error is in this file - if I don't include it, then it will compile and run.
Code:
#ifndef DATABASE_H_
#define DATABASE_H_
#include <vector>
#include <VirtualSignal.h>
typedef enum : uint16_t
{
CONFIGURATIONVERSION = 0x0000,
NUMBER_OF_SIGNALS = 0x0001
} Signal;
class DataBase
{
public:
DataBase();
VirtualSignal& getData(Signal input);
uint64_t getSize();
private:
static std::vector<VirtualSignal> signals;
};
#endif /* DATABASE_H_ */
and the implementation
Code:
#include "DataBase.h"
#define LOCAL_HOST 0x7F000001
std::vector<VirtualSignal> DataBase::signals;
DataBase::DataBase()
{
for (uint16_t n=0; n<NUMBER_OF_SIGNALS; n++)
signals.push_back(VirtualSignal(LOCAL_HOST, n));
}
VirtualSignal& DataBase::getData(Signal input)
{
return signals[input];
};
uint64_t DataBase::getSize()
{
return signals.size();
}
What am I missing?
Added after 43 minutes:
Oh. I figured it out. The variable signals is used somewhere in qt, so somehow they conflict.
Re: expected unqualified-id before public
"signals" is a Qt keyword and is used in a class declaration to define a set of methods the Qt metaobject compiler (MOC) will use to create the boilerplate code to implement Qt signals for that class. Qt Creator's pre-compile step scans source files for this and other Qt keywords and invokes MOC.
I am surprised, because I thought only classes derived from QObject which contain the Q_OBJECT macro declaration are supposed to be processed by MOC, because they are the only ones that can implement signals and slots. Maybe you are #include-ing this header file in a Qt class declaration header file and that is causing the error when MOC processes that file.
You can turn off use of the MOC keywords "signals", "slots", and "emit" by defining "no_keywords" in your .pro file "config" statement. In that case, you must use the macros Q_SIGNALS, Q_SLOTS, and Q_EMIT instead and you can use the special keywords as ordinary C++ type and variable names. That's probably not a good idea because of the confusion it will inevitably cause.