我想用我自己的版本覆蓋一個類,然後創建該類的超類引用,但我得到一個編譯錯誤。這裏是我的代碼結構超類對子類對象的引用
文件: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>)))’
我在做什麼錯?
哪條錯誤消息指向? –
@OliCharlesworth我認爲構造函數中的'* mystyle_ = new RailExtractionInteractorStyle'行。 – Grambot
您是否試圖在未初始化的指針上執行'* mystyle_ = ...'?我們不是在你的另一個問題中報道過嗎? –