我有一个带有3个静态QMap的简单的Customer类
//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;
};客户::类型是Enum,但这与问题无关
//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();这三个init函数都经过了测试,工作非常好,它们的定义完全相同,而且都是静态的。
由于某些原因,我无法取消.cpp中的名称注释。如果我这样做了,我会得到以下错误:
error: conflicting declaration 'const QMap<QString, Customer::Type> Customer::names'我试着重命名,把它移到别的地方,总是这个不起作用,我不知道为什么?
但其他人的工作没有问题。
发布于 2015-10-26 15:08:36
在cpp文件中,模板参数的顺序是错误的:
QMap<QString, Customer::Type> const Customer::names = Customer::initNames();应:
QMap<Customer::Type, QString> const Customer::names = Customer::initNames();或者,应该根据Customer::initNames()的返回类型更改头文件中的变量声明。
https://stackoverflow.com/questions/33348981
复制相似问题