[英]conflicting declaration of static QMap
我有一个简单的Customer类,带有3个静态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是一个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'
我尝试重命名,将其移动到其他地方,这总是不起作用,我也不知道为什么?
但是其他的都没问题。
在cpp文件中,模板参数的顺序错误:
QMap<QString, Customer::Type> const Customer::names = Customer::initNames();
应该:
QMap<Customer::Type, QString> const Customer::names = Customer::initNames();
或应根据Customer::initNames()
的返回类型更改头文件中的变量声明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.