需要"模板<>"语法 --> 通过函数调用类模板

requires ‘template<>’ syntax --> Call Class Template via a function

本文关键字:gt 函数调用 语法 模板 lt 需要      更新时间:2023-10-16

我有一个标题类,看起来像这样:

#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

现在我有一个看起来像这样的.cpp文件:

#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

如果我编译我的代码,我会收到此错误:

: 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
^

我不确定为什么我会收到此错误.....我想这与我使用模板类的事实有关......但我不确定这一点....

任何帮助都会很棒!

您的OpenNISegmentTrackingc++术语中称为完整的模板专业化。

换句话说,仅当模板参数是pcl::PointXYZRGBA时,才会调用模板的版本。

此类定义的正确语法是

template <>
void OpenNISegmentTracking<pcl::PointXYZRGBA>::update(const sensor_msgs::PointCloud2ConstPtr &input_cloud)
{
...
}

函数名称需要以下语法:

template<>
void OpenNISegmentTracking<pcl::PointXYZRGBA>::update(const sensor_msgs::PointCloud2ConstPtr &input_cloud)
{
// ...
}