I want to initialize a QHash<...>
inside a class. There is no problem, if the code is compiled with gcc on linux. But if I use MSVC12, I get the following error:
C2661: QHash<...>::QHash:no overloaded function takes X parameters
Minimal example:
testclass.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
testclass.cpp
#include "testclass.h"
TestClass::TestClass()
{
}
main.cpp
#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();
}
untitled.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
Do somebody of you know why MSVC throws this compiler error and how to avoid that?