![](/img/trans.png)
[英]Passing object of a Templated struct to a member function of another templated class
[英]accessing templated member function of an object that is a member of a struct
因此,我有一个包含许多成员的结构,其中包括指向PCLVisualizer对象的boost共享指针。 PCLVisualizer类是带有成员函数updatePointcloud的模板化类。 我正在尝试为模板PointType调用updatePointCloud。 请参见下面的代码:
template <typename PointType>
class A {
struct gt_data_type {
model_struct line;
PointCloudTPtr input;
PointCloudTPtr output;
int step_size;
int segment_min_pts;
vector<float> directions;
float current_direction;
vector<line_segment> seeds;
Eigen::Vector4f prev_vector;
Eigen::Vector4f current_vector;
Eigen::Vector4f p;
typename pcl::search::KdTree<PointType>::Ptr tree;
pcl::visualization::PCLVisualizer::Ptr viewer;
line_segment prev_segment;
};
gt_data_type gt_data;
void foo(PointCloudTPtr output) {
pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer("Track Viewer"));
gt_data.output = output;
gt_data.viewer = viewer;
// next line causes compile error
gt_data.viewer->updatePointCloud<PointType>(gt_data.output,"rail");
}
}
请注意,PointCloudTPtr只是不同的shared_ptr的typedef。 我在指示的行上收到以下错误: expected primary-expression before '>' token
如果我省略该结构,并直接通过执行以下操作直接调用查看器成员函数: viewer->updatePointCloud<PointType>(gt_data.output,"rail");
我的代码编译。 我不明白为什么通过结构访问查看器会有什么不同。
任何帮助表示赞赏
您发布的示例应该可以正常工作。 除非您实际上打算用类型而不是变量来调用viewer
。 但是,如果gl_data
本身是模板或依赖于模板参数 ,则编译器将不知道您是在编写函数调用还是比较表达式。 从代码的外观来看,它似乎取决于模板参数PointType
。
就像需要typename
来消除类型和变量之间的歧义一样,需要template
来消除模板和比较之间的歧义:
data.viewer->template updatePointCloud<PointType>(data.output,"rail");
您需要类型不是gt_data
的对象, gt_data
不是直接使用类的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.