Home > Enterprise >  What's the right grammar to use this member function?
What's the right grammar to use this member function?

Time:04-05

My goal is knowing the name of this "Planner" by using function "getName()"

getName() defined in Planner.cpp:

const std::string& ompl::base::Planner::getName() const
{
    return name_;
}

The way I called this function :

void ompl::geometric::SimpleSetup::clear()
{
    std::cout << base::Planner::getName() << std::endl;
    if (planner_)
        planner_->clear();
    if (pdef_)
        pdef_->clearSolutionPaths();
}

Error message I got :

/home/ubuntuvb/ws_mvit/src/ompl/src/ompl/geometric/src/SimpleSetup.cpp: In member function ‘virtual void ompl::geometric::SimpleSetup::clear()’:
/home/ubuntuvb/ws_mvit/src/ompl/src/ompl/geometric/src/SimpleSetup.cpp:87:41: error: cannot call member function ‘const string& ompl::base::Planner::getName() const’ without object
     std::cout << base::Planner::getName() << std::endl;
                                         ^
make[2]: *** [src/ompl/CMakeFiles/ompl.dir/geometric/src/SimpleSetup.cpp.o] Error 1
make[1]: *** [src/ompl/CMakeFiles/ompl.dir/all] Error 2
make: *** [all] Error 2

How should I call this function? Thank you

CodePudding user response:

This is a non static method, so you have to call it with an object.

For example, if planner_ is a pointer to an instance of a ompl::base::Planner class, then you can use

planner_->getName();

or

void ompl::geometric::SimpleSetup::clear()
{
    if (planner_ != nullptr) {
        std::cout << planner_->getName() << std::endl;
        planner_->clear();
    }
    if (pdef_ != nullptr) {
        pdef_->clearSolutionPaths();
    }
}
  • Related