I need one line to initialize a QList
This does not work,
const QList<int> & test(QList<int>() << 7 << 9); //I know, I could simply write const QList<int> test(...); without using & since QList does copy only on write...but....
const QList<int> & test(QList<int>() << 7 << 9); //I know, I could simply write const QList<int> test(...); without using & since QList does copy only on write...but....
To copy to clipboard, switch view to plain text mode
My reference points to an empty QList. Why? I thought it is equivalent to this:
tmp << 7;
tmp << 9;
const QList<int> & test(tmp); //this *is* ok
QList tmp;
tmp << 7;
tmp << 9;
const QList<int> & test(tmp); //this *is* ok
To copy to clipboard, switch view to plain text mode
And note that assuming there is a function fn somewhere,
int fn(const QList<int> & list) {return list.size();}
fn(QList<int>() << 7 << 9); //works!! isn't it the same?
int fn(const QList<int> & list) {return list.size();}
fn(QList<int>() << 7 << 9); //works!! isn't it the same?
To copy to clipboard, switch view to plain text mode
Thanks,
J
Bookmarks