c++ - 需要 'template<>' 语法 --> 通过函数调用类模板
问题描述
我有一个看起来像这样的标题类:
#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
^
我不知道为什么会出现这个错误.....我想这与我使用模板类的事实有关......但我不确定这个......
任何帮助都会很棒!
解决方案
您OpenNISegmentTracking
就是c++
所谓的完整模板专业化。
换句话说,它是模板的一个版本,只有当模板参数是 a 时才会被调用pcl::PointXYZRGBA
。
这种定义的正确语法是
template <>
void OpenNISegmentTracking<pcl::PointXYZRGBA>::update(const sensor_msgs::PointCloud2ConstPtr &input_cloud)
{
...
}
推荐阅读
- java - 使用 Spring Boot 创建 REST API
- android - 如何使用java在android中一次将otp发送给1个以上的用户?
- tableau-api - Viz 上临时数据的突出显示框
- python - 如何获取带有输入的python程序的输出,与在命令行中运行该程序完全相同
- ios - 使用嵌套导航器颤动向后滑动手势
- json - 在 mat-table 中正确显示与动态列分组的数据列表
- javascript - 使用 datables 插件和 laravel 更新一行后如何留在当前页面
- python - 如何将kafka与rest和pyspark集成?
- java - PgBouncer 抛出 PSQLException:错误:不支持的 pkt 类型:80 当通过 JDBC 在“pgbouncer”数据库上发出查询“SHOW POOLS”时
- c++ - Why is the sprintf converting only half of my uint64_t data?