[SOLVED] Initialise QVector of enums
Solved
General and Desktop
-
I have the following class:
// data.h class Data { public: Data(); // returns a QVector of type T of all elements stored template<typename T> QVector<T> ShowAllEntriesOfInput(const T &input) const; private: struct Entry { QString type; QDate date; int amount; }; QVector<Entry> entries; QStringList types; };
// data.cpp // ... Data::Data() { ////////////// // error is in the following line: // error: no match for 'operator=' (operand types are 'QVector<Data::Entry>' // and '<brace-enclosed initializer list>') entries = { // ^ ////////////// entries = { {"car", 110, QDate{2014, 03, 02}}, {"house", 80, QDate{2016, 05, 05}} }; } //....
Do you know what is wrong (error is commented in data.cpp) with my initialiser list?
-
Hi
it seems right syntax
http://stackoverflow.com/questions/15641318/anyone-give-me-an-example-to-use-qvectorqvectorstdinitializer-listt-argsbut I did wonder
struct Entry is
QString type;
QDate date;
int amount;but you say
{"car", 110, QDate{2014, 03, 02}},string, int, date ?
-
Hi!
Data::Data() : entries({ {"car", QDate{2014, 03, 02}, 110}, {"house", QDate{2016, 05, 05}, 80} }) { }
or
Data::Data() { entries = { {"car", QDate{2014, 03, 02}, 110}, {"house", QDate{2016, 05, 05}, 80} }; }
-
Hey, thanks. i just realised it a second ago that I just wrote it in the wrong order xD
Thank you anyway!!