从函数返回后向量变为空

时间:2019-07-19 17:53:57

标签: c++ function vector return tuples

我正在从在main()内部调用的函数返回向量。但是,当我访问主要返回的向量时,它在[处变为空。

我尝试在填充该函数的内部打印此vector_variable的元素和大小,它可以正常工作并提供所需的结果。从函数返回后,只有当我访问它时,它才变为空。我觉得内存访问错误,但是我不确定

vector_variable.size() = 0

这是我的输出:

inline std::tuple<cv::Mat,  std::vector<float>> 
computeCountVector( const cv::Mat &cloud) {

  std::vector<float> valid_id_vec;

  for (std::int32_t point_index{0}; point_index<1000; ++point_index) { 

      //z is already initialized
      const auto col = std::round(cloud.at<float>(point_index, 0) / z);  
      valid_id_vec.push_back(col);
      cloud.at<float>(point_index, 0)  *= 2.5;
  }
  // Skipping the rest of the code to retain clarity and reliablity
  std::cout<<"\n Size of the vec inside the function :"<<valid_id_vec.size();

  //Returning the vector
  return std::make_tuple(cloud, valid_id_vec);
}

//Inside main
void main() {

    //Delcarations
    std::vector<float> col_vec;

    //Fucntion call that returns the vector
    std::tie(cloud, col_vec) = computeCountVector(cloud); //cloud variable is computed before this piece of code
    std::cout<<"\n SIZE inside the main(): "<<col_vec.size();
}

0 个答案:

没有答案