// file.h
template <typename Key, typename Value>
class Map : public QMap<Key, Value>
{
public:
Map() : QMap<Key, Value>() { }
Map<Key, Value>& operator()(const Key & key, const Value & value)
{
this->insert(key, value);
return *this;
}
};
class A
{
public:
A()
{
qDebug() << m_list;
qDebug() << m_map;
}
private:
static QList<int> m_list;
static QMap<int, QString> m_map;
};
// file.cpp file
QList<int> A::m_list = QList<int>() << 1 << 2 << 4;
// file.h
template <typename Key, typename Value>
class Map : public QMap<Key, Value>
{
public:
Map() : QMap<Key, Value>() { }
Map<Key, Value>& operator()(const Key & key, const Value & value)
{
this->insert(key, value);
return *this;
}
};
class A
{
public:
A()
{
qDebug() << m_list;
qDebug() << m_map;
}
private:
static QList<int> m_list;
static QMap<int, QString> m_map;
};
// file.cpp file
QList<int> A::m_list = QList<int>() << 1 << 2 << 4;
QMap<int, QString> A::m_map = Map<int, QString>()(1, QString("1"))(2, QString("2"))(4, QString("4"));
To copy to clipboard, switch view to plain text mode
Bookmarks