我可以以某种方式不写出完整的限定返回类型名称吗?



我有以下嵌套类的情况:

class PS_OcTree {
public:
  // stuff ...
private:
  struct subdiv_criteria : public octree_type::subdiv_criteria {
    PS_OcTree* tree;
    subdiv_criteria(PS_OcTree* _tree) : tree(_tree) { }
    virtual Element elementInfo(unsigned int const& elem, node const* n) override;
  };
};

要在.cpp文件中实现此方法,我编写

PS_OcTree::subdiv_criteria::Element
PS_OcTree::subdiv_criteria::elementInfo(
  unsigned int const& poly_index, node const* n)
{
    // implementation goes here
}

我可以写方法的全名,但我真的还需要写返回类型的全名吗?在参数括号和函数体中,我可以访问subdiv_criteria类的名称,但这似乎不适用于返回类型。

最好,我想写一些类似的东西

Element PS_OcTree::subdiv_criteria::elementInfo(
  unsigned int const& poly_index, node const* n)
{
    // implementation goes here
}
// or
auto PS_OcTree::subdiv_criteria::elementInfo(
  unsigned int const& poly_index, node const* n)
{
    // implementation goes here
}

至少不需要我在返回类型中重复PS_OcTree::subdiv_criteria的东西。C++11 中是否有可以使用的内容?它也应该与 MSVC 2015 和 Clang 5 配合使用。

类范围查找适用于声明符 id(这是正在定义的函数的名称,即 PS_OcTree::subdiv_criteria::elementInfo )之后的任何内容,包括尾随返回类型。因此

auto PS_OcTree::subdiv_criteria::elementInfo(
  unsigned int const& poly_index, node const* n) -> Element 
{
}

相关内容

最新更新