c ++向量问题;通过参考传递东西

时间:2011-05-22 21:30:28

标签: c++ pointers vector reference temporary

所以我检查了我的指针,我真的不确定这里出了什么问题。我通过引用修改它们的函数传递2个向量向量。这是功能:

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

这就是所谓的:

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
}

错误:

/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> > > > > (*)()'

我已经尝试制作矢量指针但它没有用。我想我在某个地方使用临时变量或什么......这里有什么问题?

2 个答案:

答案 0 :(得分:6)

您不需要()默认构造变量,否则您将定义一个函数。

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

答案 1 :(得分:2)

您应该像这样初始化矢量,而不是'()':

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