-1

我的问题是:

我定义了类(生成器),在其中我定义了一个前向嵌套结构(主题和 it_set)。

我在 .cpp 文件中声明了这个嵌套类。

在此之后,我声明了第二个类(ImageGenerator),它是生成器的继承。

当我在 ImageGenerator 的声明文件中尝试时遇到问题。

反正有没有使这成为可能?

我的代码是这些:

<i>
 //base.hpp
</i>

 class generator{

 protected:

    struct topics;
    struct it_set;

    NodeHandle _nh;

    cv::Ptr<topics> _topics;
    cv::Ptr<it_set> _set;

    cv::Mat _data;

public:


   generator(ros::NodeHandle&,const std::string&,const std::string&,const std::string&);

    virtual ~generator(void);

    bool ok(void)const;


protected:

    virtual void grab(void) = 0;

};

<i>
// base.cpp
</i>

static void cam_from_sub(const std::string& _subscriber,std::string& _cam){

    std::stringstream str;

    std::vector<std::string> words;

    std::string tmp;



    for(std::string::const_iterator it = _subscriber.begin();it != _subscriber.end();it++)
        (*it != '/')?(str<<*it):(str<<std::endl);

    while(!str.eof()){
        str>>tmp;
        words.push_back(tmp);
        tmp.clear();
    }

    words.pop_back();


    for(std::vector<std::string>::iterator it = words.begin(); it != words.end();it++){
        _cam+=*it+std::string("/");
        it->clear();
    }

    words.clear();

    _cam+= std::string("camera_info");


}


struct generator::topics{

    std::string _publisher;
    std::string _subscriber;
    std::string _camera_info;

    topics(const std::string& _pub,const std::string& _sub,const std::string& _cam):_publisher(_pub),_subscriber(_sub),_camera_info(_cam){}
    topics(const std::string &_pub, const std::string &_sub):_publisher(_pub),_subscriber(_sub){cam_from_sub(_subscriber,_camera_info);}
    ~topics(void){}
};


struct generator::it_set{

    image_transport::ImageTransport _it;
    image_transport::SubscriberFilter _is;
    image_transport::Publisher _pb;
    message_filters::Subscriber<sensor_msgs::CameraInfo> _cam_info;

    it_set(NodeHandle& _nh,cv::Ptr<generator::topics>& _topics):_it(_nh),_is(_it,_topics->_subscriber,1),_cam_info(_nh,_topics->_camera_info,1){ this->_pb = this->_it.advertise(_topics->_publisher,1);}

};

generator::generator(NodeHandle & nh, const std::string & subscribe, const std::string & publish, const std::string & camera_info):_nh(nh),_topics(new topics(publish,subscribe,camera_info)),_set( new it_set(_nh,_topics)){}

generator::~generator(void){ _set.release(); _topics.release();}

bool generator::ok(void)const{ return this->_nh.ok();}

<i>
// image.hpp
</i>
class ImageGenerator : public generator{

private:

    NodeHandle _nh;

    static bool _sht;

    bool _first_sht;
    bool _is_sub;

public:

    typedef void(*function_type)(const cv::Mat&,cv::Mat&);

private:

    function_type _fun;

    virtual void callback(const sensor_msgs::ImageConstPtr&);

    virtual void grab(void);

public:

    ImageGenerator(const NodeHandle&,const std::string&,const std::string&,const std::string&,function_type);

    ~ImageGenerator(void);

    void operator>>(cv::Mat&);
    void operator<<(const cv::Mat&);


};

<i>
// image.cpp
</i>

bool ImageGenerator::_sht = false;



void ImageGenerator::grab(void){

    if(!this->_is_sub)
        this->_set->_is.registerCallback(boost::bind(&ImageGenerator::callback,this,_1));



    ros::CallbackQueue* mloop = ros::getGlobalCallbackQueue();

    while(!this->_sht)
        mloop->callAvailable(ros::WallDuration(0.1f));

    this->_sht = true;

    mloop = NULL;

    this->_is_sub = true;

}

void ImageGenerator::callback(const sensor_msgs::ImageConstPtr &msg){

    cv_bridge::CvImagePtr cv_ptr;

    cv_ptr = cv_bridge::toCvCopy(msg);

    this->_data = cv_ptr->image;
}

ImageGenerator::ImageGenerator(const NodeHandle & nh, const std::string & subscribe, const std::string & publish, const std::string & camera_info, function_type fun):_nh(nh),base::generator(_nh,subscribe,publish,camera_info),_fun(fun){ this->grab();}

ImageGenerator::~ImageGenerator(void){}

我要解决的问题是

void ImageGenerator::grab(void)

它的 :

this->_set->_is.registerCallback(boost::bind(&ImageGenerator::callback,this,_1));

编译器回答:

错误无效使用不完整类型生成器::it_set

4

1 回答 1

0

类型不完整,因为编译器没有看到该结构的定义。

如果要在 的子类中使用结构generator,则需要将它们的定义移动到generator“base.hpp”中的定义中。

于 2012-10-15T08:47:10.817 回答