views:

37

answers:

2

Hi,

I have this:

//function definition
//Point and Range are classes made of 2 ints
Point barycenter_of_vector_in_range(vector<cv::Point> &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

+3  A: 

*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.

Steve Jessop
+1 I was just about to hit `post` with pretty much the same answer.
sellibitze
Thanks! I made function to accept const and *points rather than )
nacho4d
@nacho4d: or the function could take a const reference, and you could pass it `*track`.
Steve Jessop
A: 

you are passing a pointer to a vector of points instead of the vector itself (of which the compiler implicitely takes the reference)

flownt