简体   繁体   English

使用这个成员 function 的正确语法是什么?

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

My goal is knowing the name of this "Planner" by using function "getName()"我的目标是通过使用 function “getName()” 了解此“Planner”的名称

getName() defined in Planner.cpp: Planner.cpp 中定义的 getName():

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

The way I called this function:我称这个 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?我应该如何称呼这个 function? Thank you谢谢

This is a non static method, so you have to call it with an object.这是一个非 static 方法,因此您必须使用 object 调用它。

For example, if planner_ is a pointer to an instance of a ompl::base::Planner class, then you can use例如,如果 planner_ 是指向 ompl::base::Planner class 实例的指针,那么您可以使用

planner_->getName();

or或者

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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