I have this:
//function definition
//Point and Range are classes made of 2 ints
Point barycenter_of_vector_in_range(vector<cv::Point&开发者_如何学JAVAgt; &points, cv::Range range);
//In other place...
vector<vector<Point> > tracks_; //it has some content
for (vector< vector<Point> >::const_iterator track = tracks_.begin(); track != tracks_.end(); track++) {
Point barycenter = barycenter_of_vector_in_range(&(*track), Range(0, track->size())); //Compile ERROR
}
I wonder why this is not working? I get "Invalid initialization of referenceof type ..."
Any help would be very appreciated
Thanks
*track
is a reference to const vector<Point>
, so you have two problems:
1) You're trying to pass a pointer to that into barycenter_of_vector_in_range
, which doesn't take a pointer.
2) It's const
, and barycenter_of_vector_in_range
takes a non-const reference.
you are passing a pointer to a vector of points instead of the vector itself (of which the compiler implicitely takes the reference)
精彩评论