避免限定嵌套类型名称
class ClassWithAReallyLongName {
public:
class Iterator { /* ... */ };
Iterator end();
};
使用尾随返回类型定义成员 end
:
auto ClassWithAReallyLongName::end() -> Iterator { return Iterator(); }
在没有尾随返回类型的情况下定义成员 end
:
ClassWithAReallyLongName::Iterator ClassWithAReallyLongName::end() { return Iterator(); }
在类的范围内查找尾随返回类型,而在封闭的命名空间范围中查找前导返回类型,因此可能需要冗余限定。