【发布时间】:2013-01-14 05:14:44
【问题描述】:
所以我有一个包含许多成员的结构,包括一个指向 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");
我的代码编译。我不明白为什么通过结构访问查看器会有什么不同。
感谢任何帮助
【问题讨论】:
-
这是一个非常糟糕的简单案例测试...您是否尝试使用
gt_data作为类型,或者您是否也有一个名为gt_data的变量?gt_data.output是怎么声明的,是static吗?gt_data是模板还是依赖于模板参数?您应该准备一个简单的最小测试用例来重现问题并发布... -
@K-ballo 感谢您指出我的问题。我做了一些改变。我希望这可以澄清事情。
-
它没有说明
PointType的来源,也没有说明foo依赖于它......(因为我的回答解决了你的问题,我可以猜出这些,但我不应该必须猜出你的问题是什么) -
现在问题显示了足够的上下文来实际回答!
标签: c++ templates struct shared-ptr