首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我是否可以不写出完全限定的返回类型名称?

我是否可以不写出完全限定的返回类型名称?
EN

Stack Overflow用户
提问于 2016-07-11 23:49:37
回答 1查看 69关注 0票数 2

我有以下嵌套类的情况:

代码语言:javascript
复制
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文件中实现此方法,我编写了

代码语言:javascript
复制
PS_OcTree::subdiv_criteria::Element
PS_OcTree::subdiv_criteria::elementInfo(
  unsigned int const& poly_index, node const* n)
{
    // implementation goes here
}

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

我更喜欢写这样的东西

代码语言:javascript
复制
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合作。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-11 23:58:34

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

代码语言:javascript
复制
auto PS_OcTree::subdiv_criteria::elementInfo(
  unsigned int const& poly_index, node const* n) -> Element 
{
}
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38317921

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档