1

I do not understand the difference between .h, .hpp and .cpp files in the Point Cloud Library. Here is an example with the bilateral filter, they say that:

  • include/pcl/filters/bilateral.h - will contain all definitions;
  • include/pcl/filters/impl/bilateral.hpp - will contain the templated implementations;
  • src/bilateral.cpp - will contain the explicit template instantiations.

I understand the general concept of header file and implementation, but why are there two headers file? What's the difference between the templated implementation and the explicit template instantiation?

At this moment I am working with the Kmeans class and the .hpp is not used, instead they just have the implementation in a .cpp file and they include an .h file. Why? Moreover, in kmeans.h file they give the implementation of some public member functions, not just setters and getters. I can't find the rationale behind this code.

Thank you!

ricber
  • 45
  • 6
  • just after the thing you quote they have a detailed example of what is in the .h .hpp and .cpp file. Did you read it? Please refer to that also and try to explain better what you do not understand. Currently I feel tempted to simply post the text that follows your quote as an answer... – 463035818_is_not_an_ai Jul 02 '19 at 09:52
  • template definitions cannot go into the source, but still sometimes it is a good idea to keep them seperated from the declarations, I think thats all there is to explain. See here https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file – 463035818_is_not_an_ai Jul 02 '19 at 09:56
  • maybe duplicate of: https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file – 463035818_is_not_an_ai Jul 02 '19 at 09:57
  • the class you are looking at (kmeans) is not a template, hence no need for a .hpp – 463035818_is_not_an_ai Jul 02 '19 at 09:59
  • @formerlyknownas_463035818 thank you, your last comment has clarified my confusion. Sorry for my question to be a little stupid but I am new to C++. – ricber Jul 02 '19 at 10:15
  • no need to be sorry, we all started somewhere. There are so many dark corners of c++ and almost on a daily basis I find stuff that puzzles me – 463035818_is_not_an_ai Jul 02 '19 at 10:18
  • I should also point out the entire code base for PCL was written by many people and at the very beginning there was no code review process. The `ml` module, where KMeans is from, is one of the more experimental ones of the library, so don't be surprised if you find situations breaking the convention established in the tutorials. – Sérgio Agostinho Jul 04 '19 at 18:16

1 Answers1

3

Consider that only the .h is the header file, the one that contains the definitions and the one you should include.

The implementations are in both the hpp and the cpp files.

  • hpp: contains the generic templates template<class T>,
  • cpp: contains non template functions or explicit instantiations template<pcl::PointXYZ>

Both files .h and .hpp can be merged in same file but is clearer to separate them.

Daniel GL
  • 1,229
  • 11
  • 24