避免限定巢狀型別名稱
class ClassWithAReallyLongName {
public:
class Iterator { /* ... */ };
Iterator end();
};
使用尾隨返回型別定義成員 end
:
auto ClassWithAReallyLongName::end() -> Iterator { return Iterator(); }
在沒有尾隨返回型別的情況下定義成員 end
:
ClassWithAReallyLongName::Iterator ClassWithAReallyLongName::end() { return Iterator(); }
在類的範圍內查詢尾隨返回型別,而在封閉的名稱空間範圍中查詢前導返回型別,因此可能需要冗餘限定。