【问题标题】:Virtual function not returning the value from the concrete function虚函数不从具体函数返回值
【发布时间】:2019-09-27 13:22:55
【问题描述】:

我正在编写一个我没有编码的程序,但我想(需要)理解。它在 C++ 中的虚函数上下文中。

在某一时刻,它设置了虚拟布尔函数“acceptReject”,如下所示。

virtual bool acceptReject(const Double& DeltaH) const = 0;

然后它将虚拟布尔值设置为具体的布尔函数“globalMetropolisAcceptReject”,如下所示:

bool acceptReject(const Double& DeltaH) const {
  globalMetropolisAcceptReject(DeltaH);
}

如果我直接调用 globalMetropolisAcceptReject,一切正常。如果我调用acceptReject(虚函数),它会正确输入并处理代码,但不会将值传回。相反,它总是给出错误。

对缺少什么有任何猜测吗?

【问题讨论】:

    标签: return-value virtual-functions


    【解决方案1】:

    看来我只需要在实现中添加单词return。

        bool acceptReject(const Double& DeltaH) const {
      return globalMetropolisAcceptReject(DeltaH);
    }
    

    删除问题的协议是否正确?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-23
      • 2022-11-25
      • 1970-01-01
      相关资源
      最近更新 更多