-3

In C++ coding using Point Cloud Library (PCL) I came across a new line of code that I am unfamiliar with using operator <>.

pcl::io::OctreePointCloudCompression<pcl::PointXYZRGBA>* PointCloudEncoder; 

If you notice that datatype inside "<..>". Can I get some explanation on what this means in general programming structure not just in PCL and how is this different.

David Ranieri
  • 39,972
  • 7
  • 52
  • 94
kcc__
  • 1,638
  • 4
  • 30
  • 59
  • 1
    https://en.wikipedia.org/wiki/Template_(C%2B%2B) – ajp15243 Oct 18 '14 at 06:32
  • 1
    I'm guessing `pcl` is a namespace, `pcl::io` is a namespace. `pcl::io::OctreePointCloudCompression` is a class template in `pcl::io` namespace, and `pcl::PointXYZRGBA` is a class in `pcl` namespace. That syntax is used to instantiate a class template. – R Sahu Oct 18 '14 at 06:34
  • @RSahu thanks, actually I was unfamiliar with the use of <> after the class OctreePointCloudCompression. However I just realised its a way of assigning the data type of template class. – kcc__ Oct 18 '14 at 06:45

1 Answers1

1

Symbol <> is not an operator. It is symbol for template, also known from other languages as genericity.

Template class offers you a way to have same code and specify its data type in compile time. You can think of for example Math library. Instead of write code that will work with float and double, you will write one as a template and in your program, you will decide which type (precision) you want to use by using <double> or <float> together with your library.

Martin Perry
  • 9,232
  • 8
  • 46
  • 114