我有以下嵌套类的情况:
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合作。
发布于 2016-07-11 23:58:34
类范围查找适用于声明符-id(这是所定义的函数的名称,即PS_OcTree::subdiv_criteria::elementInfo)之后的任何内容,包括尾随返回类型。因此,
auto PS_OcTree::subdiv_criteria::elementInfo(
unsigned int const& poly_index, node const* n) -> Element
{
}https://stackoverflow.com/questions/38317921
复制相似问题