我在尝试将对象引用添加到指针 vector 时遇到错误:
template <class Tpoint, class Tmodel> Tmodel ransac<Tpoint, Tmodel>::perform_fitting(const std::vector<Tpoint>& data){
std::vector<Tpoint*> also_inliers;
for (const auto& pnt : data){
if (fit_point(pnt, may_be_model) <= t){
also_inliers.push_back(&pnt); //error here
}
} // ! for range
}
来自 VS.NET 2013 的错误消息:
Error 88 error C2664: 'void std::vector>::push_back(cv::Point_ *const &)' : cannot convert argument 1 from 'const cv::Point_ *' to 'cv::Point_ *&&'
最佳答案
你捕获 pnt
作为const auto&
,但您随后尝试将其插入包含非常量指针的 vector 中。这违反了常量正确性。
要么改also_inliers
至 std::vector<const Tpoint*>
如果您不打算修改这些指针对象或通过 auto&
捕获如果您需要修改。
关于c++ - 无法将 'const T*' 转换为 'T*&&',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33667747/