0

I am having a design problem with my code. I want to be able to an std::map with a key value pair of pcl::PointCloud and LidarFile(my own created class), but that requires the < operator to be overloaded since std::map uses comparisons, OR the std::less function template overloaded. The code relating to pcl::PointCloud is in a separate translation unit, and I would rather not modify it, but in order to specify a template specialization for pcl::PointCloud it seems like I have to. So how do I specify the < operator for pcl::PointCloud if it is in a separate translation unit because the error I get now? I am getting both the error

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__functional_base:63:21: error: 
      invalid operands to binary expression ('const
      pcl::PointCloud<pcl::PointXYZRGB>' and 'const
      pcl::PointCloud<pcl::PointXYZRGB>')
        {return __x < __y;}

and I assume this is because I need to overload the < operator and also get this error:

/Users/wfehrnstrom/Demeter/Map.cpp:3:21: error: explicit specialization of
      'std::__1::less<pcl::PointCloud<pcl::PointXYZRGB> >' after instantiation
  template<> struct less<pcl::PointCloud<pcl::PointXYZRGB> >{
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Could anyone guide me on correct design principle in this situation or possibly correct any misguided assumptions I have in this situation? I really appreciate it.

wfehrnstrom
  • 329
  • 2
  • 17
  • `std::map` takes a comparator as its third template parameter. It doesn't have to be `std::less`. In any case, you can forward-declare a template specialization in the header, and implement it elsewhere. – Igor Tandetnik Aug 27 '16 at 18:01
  • How would you suggest overloading a comparator in this instance so that std::map does not throw the invalid operands error? – wfehrnstrom Aug 27 '16 at 18:03
  • 1
    The same way as in any other instance. `class ComparePointClouds { bool operator() (const PointCloud& pc1, const PointCloud& pc2) const; }; std::map myMap;` – Igor Tandetnik Aug 27 '16 at 18:04
  • 1
    *"The code relating to `pcl::PointCloud` is in a separate translation unit"* But wait. `PointCloud` is a template, apparently. You do realize that templates must be implemented in header files, so that their definitions are visible to the compiler at the point of use, right? http://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file – Igor Tandetnik Aug 27 '16 at 18:07

0 Answers0