PDA

View Full Version : Multi-dimensional objects array



matulik
27th April 2010, 09:45
Hello.
I want to create multi-dimensional array of objects, but I have problem with it.
For example:

QTableWidgetItem *item = new QTableWidgetItem[10][10];
call me:

(...)mainwindow.cpp:54: error: cannot convert ‘QTableWidgetItem (*)[10]’ to ‘QTableWidgetItem*’ in initialization

What else do it to resolve error?

Kumosan
27th April 2010, 09:56
This is on so many levels wrong that just telling you the solution would not help you at all. Maybe you should read the basics on arrays in C++ first:

http://www.cplusplus.com/doc/tutorial/arrays/
http://www.exforsys.com/tutorials/c-plus-plus/c-multidimensional-arrays.html
http://www.cplusplus.com/forum/articles/7459/

csaken
27th April 2010, 10:02
You cannot allocate memory for multi-dimensional array like that,it is a bit more complicated.

You could just use a Vector class which makes life easier:


QVector<QVector<QTableWidgetItem*> > vector(10, QVector<QTableWidgetItem*>(10));

vector[2][3] = <YourPointerHere>


and also adds benefits like posibility to resize your array.

tuannp
23rd October 2011, 02:20
thanks you so much!!!:o:o:o