0

I have a header class that looks like this:

#ifndef A_H__
#define A_H__

using namespace pcl::tracking;

namespace ball_tracking_cloud
{

template <typename PointType>
class OpenNISegmentTracking
{
public:
  //...

protected:
   void update(const sensor_msgs::PointCloud2ConstPtr &input_cloud);

  }; // end of class

} // end namespace

#endif

And now I have a .cpp file that looks like this:

#include <ball_tracking_cloud/particle_detector.h>

bool init = true;


namespace ball_tracking_cloud
{
void OpenNISegmentTracking<pcl::PointXYZRGBA>::update(const sensor_msgs::PointCloud2ConstPtr &input_cloud)
{
    pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGBA>);
    pcl::fromROSMsg(*input_cloud, *cloud);

    if(init)
    {
        v.run ();
        init=false;
    }

   v.cloud_cb(cloud);
}

} // end of namespace

If I compile my code I get this error:

: error: specializing member ‘ball_tracking_cloud::OpenNISegmentTracking<pcl::PointXYZRGBA>::update’ requires ‘template<>’ syntax
 void OpenNISegmentTracking<pcl::PointXYZRGBA>::update(const sensor_msgs::PointCloud2ConstPtr &input_cloud)
      ^
/hri/localdisk/markus/ros-alex/src/ball_tracking/ball_tracking_cloud/src/particle_detector.cpp:38:1: error: expected ‘}’ at end of input
 } // end of namespace
 ^

I am not sure why I get this error..... I guess it has something to do with the fact that I use a template class ..... but I am not sure about this....

Any help would be great!

sqp_125
  • 538
  • 6
  • 21

2 Answers2

2

Your OpenNISegmentTracking is what in c++ terms is called a full template specialization.

In other words, it's a version of your template that will be invoked, only when the template parameter is a pcl::PointXYZRGBA.

The proper syntax for such a definition is

template <>
void OpenNISegmentTracking<pcl::PointXYZRGBA>::update(const sensor_msgs::PointCloud2ConstPtr &input_cloud)
{
    ...
}
super
  • 12,335
  • 2
  • 19
  • 29
1

You need this syntax for the function name:

template<>
void OpenNISegmentTracking<pcl::PointXYZRGBA>::update(const sensor_msgs::PointCloud2ConstPtr &input_cloud)
{
    // ...
}
VLL
  • 9,634
  • 1
  • 29
  • 54