Reputation: 5556
I have a variable in the argument of a function that is defined like this:
QVector< QVector<qreal> > *var;
In a certain point of the code I want to do this:
*var[i][j] = some_value.
However this does not compile because
error: no match for ‘operator*’ in ‘*(var + ((long unsigned int)(((long unsigned int)row) * 8ul)))->QVector::operator[] with T = QVector’
How do I properly reference the value so that it is modified? (The idea is that the parameter passed in the function is really modified.)
Upvotes: 2
Views: 2388
Reputation: 7687
You need to put *var
in parentheses:
(*var)[i][j] = some_value;
Though why are you using a pointer to a QVector
? Since QVector
is part of Qt's generic containers family, it uses implicit sharing. This means that if you pass-by-value instead, you'll only perform a shallow copy, which is to say that you'll effectively only be passing the thin book-keeping part of the data structure - a pointer to a larger block of data which exists elsewhere.
Upvotes: 4