векторная проблема с ++; передача вещи по ссылке - PullRequest
2 голосов
/ 23 мая 2011

Итак, я проверил свои указатели, и я действительно не уверен, что здесь происходит не так. Я передаю 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 ]

6 голосов
/ 23 мая 2011

Вам не нужно () для создания переменной по умолчанию, в противном случае вы определяете функцию.

vector<vector<int> >  fingertips;
vector<vector<Point> >  hands;
//                           ^ loose the ()s
2 голосов
/ 23 мая 2011

Вы должны инициализировать векторы следующим образом, без '()':

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