James Gilles
James Gilles

Reputation: 694

c++ vector problem; passing stuff by reference

So I've checked my pointers and I'm really not sure what's going wrong here. I'm passing 2 vectors of vectors by reference to a function that modifies them. Here's the function:

bool imageToTips( Mat& img,
  vector<vector<int> > & fingertips,
  vector<vector<Point> > & hand,
  double epsilon,
  double theta){
      //code 
}

And here's where it's called:

Mat depth = _depth;
Mat image = depth.clone();
Mat decon = depth.clone();
vector<vector<int> >  fingertips();
vector<vector<Point> >  hands();
double epsilon = 50;
double theta = 30;
if (fs::imageToTips(decon, fingertips, hands, epsilon, theta)) 
{
    drawContours(image, hands, -1, Scalar(255,0,0,0));
    imshow("KinectFingerProcessing", image);
    //more code
}

The errors:

/FingerLocator2/main.cpp:47: error: invalid initialization of non-const reference of type 'std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&' from a temporary of type 'std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > (*)()'

/FingerLocator2/main.cpp:49: error: invalid initialization of reference of type 'const std::vector<std::vector<cv::Point_<int>, std::allocator<cv::Point_<int> > >, std::allocator<std::vector<cv::Point_<int>, std::allocator<cv::Point_<int> > > > >&' from expression of type 'std::vector<std::vector<cv::Point_<int>, std::allocator<cv::Point_<int> > >, std::allocator<std::vector<cv::Point_<int>, std::allocator<cv::Point_<int> > > > > (*)()'

I've tried making the vector pointers and it hasn't worked. I think I'm using a temp variable somewhere or something… what's wrong here?

Upvotes: 2

Views: 1249

Answers (2)

Colin Thomsen
Colin Thomsen

Reputation: 1806

You should be initializing the vectors like this, without the '()':

vector<vector<int> >  fingertips;
vector<vector<Point> >  hands;

Upvotes: 2

kennytm
kennytm

Reputation: 523584

You don't need the () to default-construct a variable, otherwise you're defining a function.

vector<vector<int> >  fingertips;
vector<vector<Point> >  hands;
//                           ^ loose the ()s

Upvotes: 6

Related Questions