简体   繁体   中英

Can I somehow not write out the full qualified return type name?

I have the following case of a nested class:

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

To implement this method in the .cpp file, I write

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

I'm fine with writing the full name of the method, but do I really also need to write the full name of the return type? Inside the parameter parentheses and the function body, I can access names of the subdiv_criteria class, but that doesn't seem to work for the return type.

Preferrably, I'd like to write something like

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
}

At least something that doesn't require me to repeat PS_OcTree::subdiv_criteria in the return type. Is there something in C++11 that I can use? It should work with MSVC 2015 and Clang 5 as well.

Class-scope lookup applies to anything after the declarator-id (which is the name of the function being defined, ie, PS_OcTree::subdiv_criteria::elementInfo ), including a trailing return type. Hence,

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

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