c++向量问题;通过引用传递东西
所以我检查了我的指针,我真的不确定这里出了什么问题。我通过引用修改它们的函数来传递两个向量。这是函数:
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> > > > > (*)()'
我尝试过创建向量指针,但没有成功。我想我在某个地方使用了临时变量……这里出了什么问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不需要
()
来默认构造变量,否则您将定义一个函数。You don't need the
()
to default-construct a variable, otherwise you're defining a function.您应该像这样初始化向量,不带“()”:
You should be initializing the vectors like this, without the '()':