2017-04-18 71 views
0

我与Point Cloud Library工作,我试图避免重蹈以下行为:如何使用抽象类型的C++指针指向具体类?

pcl::PointCloud<pcl::PointXYZRGB>::Ptr filter(PointCloud<pcl::PointXYZRGB>::Ptr input_cloud) { 
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZRGB>); 
    subclass.setInputCloud(input_cloud); 
    subclass.filter(*cloud_filtered); 
    return cloud_filtered; 
} 

我希望使用基于此example的东西,沿着线:

pcl::Filter<PointXYZRGB>* f; 
pcl::Subclass<PointXYZRGB> s; //where s is an implementation of f 
f = &s; 

pcl::PointCloud<pcl::PointXYZRGB>::Ptr filter(PointCloud<pcl::PointXYZRGB>::Ptr input_cloud) { 
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZRGB>); 
    f->setInputCloud(input_cloud); 
    f->filter(*cloud_filtered); 
    return cloud_filtered; 
} 

但是,编译器报告的这不会按照f does not name a type进行编译。

我假设这是由于pcl::Filter是一个抽象类?

该方法是否适用于示例类,如pcl::VoxelGrid或者是否有替代方法?

任何帮助非常感谢!

+0

我闻[缺少'typename'(http://stackoverflow.com/questions/8584431/why-is-the-keyword-typename-需要之前合格的依赖名称和不是b) – dhke

+0

你是否试图在功能之外执行'f =&s;'? – aschepler

+0

通常你在编译器找不到类时会出现这个错误,把f作为抽象类对我来说是非常正常的我认为问题出在include或类似的东西上,确定你的include是在正确的地方? –

回答

0

f = &s;应该移到一个函数中。

在这种情况下,它被移到派生子类的构造函数中。

信用和感谢回答用户,aschepler