【发布时间】:2020-12-16 03:07:21
【问题描述】:
我知道有人在这方面提出过类似的问题,但我似乎无法找到解决我确切问题的方法。我有一个 LinkedList 和 LinkedListIterator 类的结构。
template <typename T>
class LinkedList
{
public:
template <typename NodeType>
class LinkedListIterator
{
public:
const LinkedListIterator<NodeType>& operator++();
}
};
我正在尝试在单独的文件中实现operator++() 函数,我的尝试如下。
template <typename T>
template <typename NodeType>
const typename LinkedList<T>::LinkedListIterator<NodeType>&
LinkedList<T>::LinkedListIterator<NodeType>::operator++()
{
// Implementation here
}
现在当我尝试使用这个类时,我的编译器会抛出一个错误,提示 non-template ‘LinkedListIterator’ used as template。现在我知道我必须在这个函数的定义中使用typename,因为我有依赖范围发生。但我似乎无法解决这个问题。我不明白这如何被视为non-template。
【问题讨论】:
-
在这里编译得很好gcc.godbolt.org/z/Pr366s
标签: c++ templates iterator typename