0

I have a simple Customer class with 3 static QMap

//customer.h

class Customer : public QObject
{
    Q_OBJECT
public:
    static QMap<Customer::Type, QString> const names;
    static QMap<QString, Customer::Type> const keywords;
    static QMap<Customer::Type, QString> const debugStrings;
};

Customer::Type is a Enum, but this is not relevant to the problem

//customer.cpp

//QMap<QString, Customer::Type> const Customer::names = Customer::initNames();
QMap<QString, Customer::Type> const Customer::keywords = Customer::initKeywords();
QMap<Customer::Type, QString> const Customer::debugStrings = Customer::initDebugStrings();

all three init function have been tested and work perfectly fine, they are defined exactly the same way and are all static

For some reason, I cannot uncomment the names in .cpp. If I do, I get the following error :

error: conflicting declaration 'const QMap<QString, Customer::Type> Customer::names'

I tried renaming, moving it somewhere else, it always is this one that doesn't work, and I don't know why ?

But the other ones worked with no issue..

demonplus
  • 5,613
  • 12
  • 49
  • 68
BlueMagma
  • 2,392
  • 1
  • 22
  • 46
  • Do you have a class method with the same name? Anyway, you should provide full class declaration. – hank Oct 26 '15 at 15:06

1 Answers1

7

In your cpp file you have the template parameters in the wrong order:

QMap<QString, Customer::Type> const Customer::names = Customer::initNames();

should be:

QMap<Customer::Type, QString> const Customer::names = Customer::initNames();

Or the variable declaration in your header file should be changed depending on the return type of Customer::initNames()

agold
  • 6,140
  • 9
  • 38
  • 54