简体   繁体   中英

accessing templated member function of an object that is a member of a struct

So I have a structure which hold many members including a boost shared pointer to a PCLVisualizer object. The PCLVisualizer class is a templated class with a member function updatePointcloud. I am trying to call updatePointCloud for template PointType. Please see code below:

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");
    }

}

Note that PointCloudTPtr is just a typedef for different shared_ptr. I get the following error at the line indicated: expected primary-expression before '>' token

If I omit the struct and call the viewer member function directly by doing this: viewer->updatePointCloud<PointType>(gt_data.output,"rail");

my code compiles. I don't understand why accessing the viewer through a struct makes any difference.

Any help is appreciated

The sample you posted should work fine. Unless you actually meant to call viewer on a type instead of a variable . However, if gl_data is itself a template or dependent on a template parameter , then the compiler wouldn't know if you are writing a function call or a comparison expression. And from the looks of your code, it seems that it is dependent on the template parameter PointType .

Just as typename is needed to disambiguate between a type and a variable, template is needed to disambiguate between a template and a comparison:

data.viewer->template updatePointCloud<PointType>(data.output,"rail");

您需要类型不是gt_data的对象, gt_data不是直接使用类的名称。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM