我想QHash<...>
在一个类中初始化一个。没有问题,如果代码是在linux上用gcc编译的。但是如果我使用 MSVC12,我会收到以下错误:
C2661:QHash<...>::QHash:没有重载函数采用 X 参数
最小的例子:
测试类.h
#ifndef TESTCLASS_H
#define TESTCLASS_H
#include <QHash>
#include <QString>
class TestClass
{
public:
TestClass();
QHash<QString, QString> myHash = {{"Hi", "Hello"},
{"test", "Test"}};
};
#endif // TESTCLASS_H
测试类.cpp
#include "testclass.h"
TestClass::TestClass()
{
}
主文件
#include <QCoreApplication>
#include <QDebug>
#include "testclass.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
TestClass test;
qDebug() << test.myHash;
return a.exec();
}
无标题.pro
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
DEFINES += Q_COMPILER_INITIALIZER_LISTS
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp \
testclass.cpp
HEADERS += \
testclass.h
你们中有人知道为什么 MSVC 会抛出这个编译器错误以及如何避免这种情况吗?