首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >静态QMap的冲突声明

静态QMap的冲突声明
EN

Stack Overflow用户
提问于 2015-10-26 15:01:23
回答 1查看 1.5K关注 0票数 0

我有一个带有3个静态QMap的简单的Customer类

代码语言:javascript
复制
//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,但这与问题无关

代码语言:javascript
复制
//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中的名称注释。如果我这样做了,我会得到以下错误:

代码语言:javascript
复制
error: conflicting declaration 'const QMap<QString, Customer::Type> Customer::names'

我试着重命名,把它移到别的地方,总是这个不起作用,我不知道为什么?

但其他人的工作没有问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-26 15:08:36

在cpp文件中,模板参数的顺序是错误的:

代码语言:javascript
复制
QMap<QString, Customer::Type> const Customer::names = Customer::initNames();

应:

代码语言:javascript
复制
QMap<Customer::Type, QString> const Customer::names = Customer::initNames();

或者,应该根据Customer::initNames()的返回类型更改头文件中的变量声明。

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33348981

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档