this isn't quite working out. Let's see if we can collectively expand our knowledge on this one. Okay:
vector<vector<Point>> aVectorOfPoints
int main(){
someConstructor(&aVectorOfPoints)
}
someConstructor(vector<vector<Point>>* aVectorOfPoints){
functionOne(aVectorOfPOints);
}
functionOne(vector<vector<Point>>* aVectorOfPOints){
aVectorOfPoints[i][j] = getPointFromClass();
}
//functionX(...){...}
I'm getting some error underneath the assignment in functionOne. How can I better do this? Thanks.
The specific error is "No operator '=' matches these operands".
Use references instead of pointers:
someConstructor( vector<vector<Point>> &aVectorOfPoints) {
and the same for functionOne
.
Your mistake is that aVectorOfPoints[i]
indexes the pointer by i
. If using pointers you'd need to dereference the pointer first before doing that, by writing (*aVectorOfPoints)[i][j]
.
Why is this wrong?
aVectorOfPoints[i][j] = getPointFromClass();
type of aVectorOfPoints
is vector<vector<Point>>*
.
type of aVectorOfPoints[i]
is vector<vector<Point>>
.
type of aVectorOfPoints[i][j]
is vector<Point>
.
A Point
cannot be assigned to a vector<Point>
. Hence the compiler error.
Perhaps you meant to use:
(*aVectorOfPoints)[i][j] = getPointFromClass();
You can simplify the code by passing references.
int main(){
someConstructor(aVectorOfPoints)
}
someConstructor(vector<vector<Point>>& aVectorOfPoints){
functionOne(aVectorOfPOints);
}
functionOne(vector<vector<Point>>& aVectorOfPOints){
aVectorOfPoints[i][j] = getPointFromClass();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.