我试图用我自己的版本覆盖一个类,然后创建一个类的超类引用,但我收到编译错误。这是我的代码结构
文件:RailExtractionInteractorStyle.h(这是我继承超类PCLVisualizerInteractor的子类)
#include<pcl/visualization/interactor_style.h>
class RailExtractionInteractorStyle : public pcl::visualization::PCLVisualizerInteractorStyle
{
public:
RailExtractionInteractorStyle();
};
文件:RailExtractionInteractor.cpp:
#include "RailExtractionInteractorStyle.h"
RailExtractionInteractorStyle::RailExtractionInteractorStyle()
: pcl::visualization::PCLVisualizerInteractorStyle()
{
// just calling super constructor for now
}
文件:CloudPointPicker.hpp(使用RailExtractionInteractorStyle类的任意类)
#include "RailExtractionInteractorStyle.h"
template <typename PointT>
class CloudPointPicker {
protected:
PointCloudTConstPtr cloud_;
boost::shared_ptr<pcl::visualization::PCLVisualizer> myview_;
//attempting to write my own interactor
RailExtractionInteractorStyle* mystyle_;
public:
CloudPointPicker() {
*mystyle_ = new RailExtractionInteractorStyle;
}
CloudPointPicker构造函数中的语句给出了以下错误:
error: no match for ‘operator=’ in ‘*((CloudPointPicker<pcl::PointXYZ>*)this)->CloudPointPicker<pcl::PointXYZ>::mystyle_ = (operator new(480u), (<statement>, ((RailExtractionInteractorStyle*)<anonymous>)))’
我做错了什么?
答案 0 :(得分:0)
您必须删除此行开头的*:
*mystyle_ = new RailExtractionInteractorStyle;
operator new直接应用于指针,不需要取消引用它。