PDA

View Full Version : vector of vector



mickey
4th June 2006, 22:00
Hi, I need declare a vector of vector; is it possible? thanks


vector<QSpinBox*> sbz;
vector<QSpinBox*> sby;
vector<QSpinBox*> sbz;
vector<vector> sb; //error

jacek
4th June 2006, 23:04
Hi, I need declare a vector of vector; is it possible?
Yes, but you must specify the type which the inner vector will hold.

mickey
4th June 2006, 23:27
Ok, but i don't know how push in it elements:


vector<QSpinBox> sb;
sb.push_back(sbx); //error


Another Q: Wich is better (between 2 below)? Thanks


vector<QSpinBox*> sbz;
vector<QSpinBox> sbz;

jacek
4th June 2006, 23:51
You can't copy Qt widgets, so you can't have a vector of spin boxes. Use a vector of pointers instead.

mickey
5th June 2006, 00:41
if you referred to this, don't compile...


vector<QSpinBox*> sbx;
vector<QSpinBox*> sb;
sb.push_back(sbx); //error


Maybe this?


vector<QSpinBox**> sb;
sb.push_back(&sbx[0]);

jacek
5th June 2006, 00:50
if you referred to this, don't compile...
If you want a vector of vectors of pointers to spin boxes you need:

vector<QSpinBox*> sbx;
vector< vector<QSpinBox*> > sb;
sb.push_back(sbx); // no error

kroenecker
29th June 2006, 14:39
Jacek,

How does that work again? When setting an object equal to another object in c++, it doesn't call the copy constructor, but rather the operator =, right? So in either case we can't "copy" widgets? That is, even when evoking the copy constructor?

fullmetalcoder
29th June 2006, 15:19
Jacek,

How does that work again? When setting an object equal to another object in c++, it doesn't call the copy constructor, but rather the operator =, right? So in either case we can't "copy" widgets? That is, even when evoking the copy constructor?

widgets can't be copied! All you can use is a pointer (or a reference depending what you want to do, but a pointer is better anyway) to them that can be used to modify them.

jacek
29th June 2006, 15:19
So in either case we can't "copy" widgets?
Yes, you can't copy widgets, but here you have a vector of pointers to widgets.