使用 class 之外的模板 class 中的 typedef 成员作为成员函数的 return 类型

Use typedef member from a template class outside of the class as return type for member function

我应该用什么代替三个问号?

template <class T>
class B_T
{
public:
    typedef _Array_iterator<T, uint32> iterator;

    iterator begin();
};

template <class T>
??? B_T<T>::begin()
{
    // code here
}

这个:

template <class T>
typename B_T<T>::iterator B_T<T>::begin()
{
    // code here
}

需要 typename 关键字,因为 iterator 取决于模板参数,并且在 this SO 答案中恢复。

template<typename T>
typename B_T<T>::iterator B_T<T>::begin();

您有多种选择:

template <class T>
_Array_iterator<T, uint32> B_T<T>::begin() {/**/}

但为什么在那种情况下使用 typedef ;-)
否则经典方式:

template <class T>
typename B_T<T>::iterator B_T<T>::begin() {/**/}

从 C++11 开始:

template <class T>
auto B_T<T>::begin() -> iterator {/**/} // No need of `typename B_T<T>::` before `iterator`.