What is wrong in my code?
#include <QVector>
int main()
{
QVector<int> v;
printf("v.size()=%u\n", v.size());
v.reserve(2);
printf("v.size()=%u\n", v.size());
}
#include <QVector>
int main()
{
QVector<int> v;
printf("v.size()=%u\n", v.size());
v.reserve(2);
printf("v.size()=%u\n", v.size());
}
To copy to clipboard, switch view to plain text mode
Result:
v.size()=0
v.size()=0
v.size()=0
v.size()=0
To copy to clipboard, switch view to plain text mode
I expected that reserve() does allocate the required memory, as resize() does, so how does reserve() work actually?
Bookmarks