【发布时间】:2015-10-26 15:01:23
【问题描述】:
我有一个带有 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();
所有三个初始化函数都已经过测试并且工作正常,它们的定义方式完全相同并且都是静态的
出于某种原因,我无法取消注释 .cpp 中的名称。如果这样做,我会收到以下错误:
error: conflicting declaration 'const QMap<QString, Customer::Type> Customer::names'
我试过重命名,把它移到别的地方,总是这个不起作用,我不知道为什么?
但其他的工作没有问题..
【问题讨论】:
-
你有同名的类方法吗?无论如何,你应该提供完整的类声明。