
Originally Posted by
squeegedog
Sorry, I thought it was clear that I was showing the different errors received when I ran the line
pathfix = &p1map
pathfix = &p1map
To copy to clipboard, switch view to plain text mode
Based on how I declared the variable pathfix.
// Fails because you are assigning a pointer to a non-pointer variable.
QVector< QVector<MapSpace> > pathfix;
pathfix = &p1map;
// Does not fail. Your error message is from unrelated code.
QVector< QVector<MapSpace> >* pathfix;
pathfix = &p1map;
// Fails because a pointer-to-QVector<...> is not a pointer-to-pointer-to-QVector<...>
QVector< QVector<MapSpace> >** pathfix;
pathfix = &p1map;
// Fails because you are assigning a pointer to a non-pointer variable.
QVector< QVector<MapSpace> > pathfix;
pathfix = &p1map;
// Does not fail. Your error message is from unrelated code.
QVector< QVector<MapSpace> >* pathfix;
pathfix = &p1map;
// Fails because a pointer-to-QVector<...> is not a pointer-to-pointer-to-QVector<...>
QVector< QVector<MapSpace> >** pathfix;
pathfix = &p1map;
To copy to clipboard, switch view to plain text mode
The errors with ispassable() was showing that I could not access the public member functions of the Mapspace when instantiating the pointer in that manner.
This is one way you would access an MapSpace function given a pointer to the nested vectors:
#include <QtCore>
struct MapSpace {
void func() { qDebug() << Q_FUNC_INFO;}
void constFunc() const { qDebug() << Q_FUNC_INFO; }
};
void someFunc(QVector< QVector<MapSpace> >* v) {
qDebug() << Q_FUNC_INFO;
for (int i = 0; i < v->size(); ++i) { // outer vector
for (int j = 0; j < v->at(i).size(); ++j) { // inner vector
qDebug() << i << j;
// +- returns const reference to a QVector<MapSpace>
// | + returns const reference to a MapSpace
// | | + on which we call
// V V V
v->at(i).at(j).constFunc();
// +- returns non const reference to a QVector<MapSpace>
// | + returns non-const reference to a MapSpace
// | | + on which we call
// V V V
v->operator[](i).operator[](j).func();
}
}
}
int main(int argc, char **argv) {
QVector< QVector<MapSpace> > p1map;
p1map << QVector<MapSpace>(2);
p1map << QVector<MapSpace>(3);
someFunc(&p1map);
return 0;
}
#include <QtCore>
struct MapSpace {
void func() { qDebug() << Q_FUNC_INFO;}
void constFunc() const { qDebug() << Q_FUNC_INFO; }
};
void someFunc(QVector< QVector<MapSpace> >* v) {
qDebug() << Q_FUNC_INFO;
for (int i = 0; i < v->size(); ++i) { // outer vector
for (int j = 0; j < v->at(i).size(); ++j) { // inner vector
qDebug() << i << j;
// +- returns const reference to a QVector<MapSpace>
// | + returns const reference to a MapSpace
// | | + on which we call
// V V V
v->at(i).at(j).constFunc();
// +- returns non const reference to a QVector<MapSpace>
// | + returns non-const reference to a MapSpace
// | | + on which we call
// V V V
v->operator[](i).operator[](j).func();
}
}
}
int main(int argc, char **argv) {
QCoreApplication app(argc, argv);
QVector< QVector<MapSpace> > p1map;
p1map << QVector<MapSpace>(2);
p1map << QVector<MapSpace>(3);
someFunc(&p1map);
return 0;
}
To copy to clipboard, switch view to plain text mode
The problem I'm facing with using your proposed solution is that this methodology of determining which map to use will be used in several functions, and most of them are being called by a class that is not aware of the 2d vectors
Not sure what you mean.
Bookmarks