【发布时间】:2016-11-14 01:10:05
【问题描述】:
我有以下嵌套类的情况:
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。
【问题讨论】:
-
在 C++11 中,您可以编写
auto PS_OcTree::subdiv_criteria::elementInfo( unsigned int const& poly_index, node const* n) -> Element。如果 MSVC 支持,则 IDK
标签: c++ c++11 visual-c++ clang code-duplication