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, i.e., 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
{
}