简体   繁体   中英

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

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

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();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM