ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Found out what caused the error: use of deleted function xxx errors on @ahendrix 's answer. RosIntrospection::Parser instance can't be copied (similar to std::map instances). You can't do parser1 = parser2;. I don't have a deep understanding on how this happens but if someone come across a similar issue, hope this'll be of help.

Found out what caused the error: use of deleted function xxx errors on @ahendrix 's answer. RosIntrospection::Parser instance can't be copied (similar to std::map instances). You can't do parser1 = parser2;. I don't have a deep understanding on how this happens but if someone come across a similar issue, hope this'll be of help.help.

Below is my working solution. For my application, I don't need to pass the parser from main so I am using a local parser for each class instance.

class Foo {
  public:
    Foo(std::string topic) 
     : topic_(topic)
    {
        ros::NodeHandle n;
        sub = n.subscribe(topic_, 10, &Foo::topicCallback, this);
    }

    void topicCallback(const topic_tools::ShapeShifter::ConstPtr& msg)
    {
        ---EXAMPLE CODE---
    }
  private:
    std::string topic_;
    RosIntrospection::Parser& parser;
    ros::Subscriber sub;
};

main(){
    ---SOME CODE---
    Foo *f;
    std::vector<Foo*> foos;
    for (auto &info : topics)
    {
        f = new Foo(info);
        foos.push_back(f);
    }
    ---SOME MORE CODE---
}