Home > Enterprise >  no matching function for call to ‘std::set<unsigned int>::insert(std::size_t&)
no matching function for call to ‘std::set<unsigned int>::insert(std::size_t&)

Time:10-27

I am working on migrating my package from ros melodic to ros noetic. while doing it I got compilation error in PCL library during cmake. The package is too big I am giving some code where error happened. Any guidance would be helpfull. This is myfile.cpp

std::vector<bool> ignore_labels;

ignore_labels.resize(2);
ignore_labels[0] = true;
ignore_labels[1] = false;

//TODO commented that out i think we have to fix the error
ecc->setExcludeLabels(ignore_labels);

'''

and this is the PCL-1.10 library file it called at line ecc->setExcludeLabels(ignore_labels); here error occured,

''' brief Set labels in the label cloud to exclude. param[in] exclude_labels a vector of bools corresponding to whether or not a given label should be considered

  void
  setExcludeLabels (const std::vector<bool>& exclude_labels)
  {
    exclude_labels_ = boost::make_shared<std::set<std::uint32_t> > ();
    for (std::size_t i = 0; i < exclude_labels.size ();   i)
      if (exclude_labels[i])
        exclude_labels_->insert (i);
  }

'''

the error is

/usr/include/pcl-1.10/pcl/segmentation/euclidean_cluster_comparator.h:256:13: error: no matching function for call to ‘std::set::insert(std::size_t&) const’ 256 | exclude_labels_->insert (i); | ^~~~~~~~~~~~~~~ In file included from /usr/include/c /9/set:61,

CodePudding user response:

I have looked into the source code for this library, here is the issue:

enter image description here

The type is a typedef: enter image description here

The issue is that the object itself is a shared_ptr<const std::set<std::uint32_t>> the code you have posted is allocating the object, but also calling std::set::insert on an instance of const std::set, which does not exist because by std::set::insert modifies the state of the std::set

notice the const at the end of the compiler error: ‘std::set::insert(std::size_t&) const it means you are trying to call a version of insert that is const, which does not exist (and cannot exist)

Here you can learn more about const-qualified methods

CodePudding user response:

You cannot add an element of type size_t (usually UInt64) to set<UInt32> because you cannot compare UInt64 and UInt32.

CodePudding user response:

The error occurs because a variable of size_t is tried to insert in the container exclude_labels_. Please cast the variable i to uint32_t and then try to insert in the container exclude_labels_.

  • Related