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

(http://stackoverflow.com/questions/8584431/why-is-the-keyword-typename- ['typename' 실종]를 required-before-qualified-dependent-names-and-not-b) – dhke

+0

함수 외부에서'f = & s; – aschepler

+0

컴파일러가 클래스를 찾을 수 없을 때 보통이 오류가 발생합니다. f가 내게있는 추상 클래스로 f를 가지는 것이 정상입니다. 문제가 include 또는 something에 있다고 생각합니다. 포함 할 것이 확실합니다. 바른 장소? –

답변

0

라인 f = &s;은 함수 내에서 이동되어야합니다.

이 경우 파생 된 하위 클래스의 생성자 내로 이동되었습니다.

신용 및 사용자에 대한 답을 주셔서 감사합니다, aschepler 나는 냄새

관련 문제