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..

1
  • Do you have a class method with the same name? Anyway, you should provide full class declaration.
    – hank
    Oct 26, 2015 at 15:06

1 Answer 1

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()

3
  • I feel really dumb now :-) thank you so much, I've been loosing my head around this for almost an hour
    – BlueMagma
    Oct 26, 2015 at 15:11
  • This kind of mistake is easy to miss :)
    – agold
    Oct 26, 2015 at 15:15
  • classic copy paste mistake :)
    – Marek R
    Oct 26, 2015 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.