我在编译一个带有嵌套迭代器和 const_iterator 类的双向链表类时遇到问题。
我不熟悉使用模板语法,这有点像一场噩梦。现在,我的每个函数似乎都出现错误,最后出现链接器错误。这让我觉得我的标题有问题,或者包含标题,或者与函数的签名有关。
我的标题示例是:
class const_iterator {
friend RecentList;
Node* curr_;
const_iterator(Node* p);
public:
const_iterator();
const_iterator operator++() const;
对应的实现是:
template <typename T>
RecentList<T>::const_iterator::const_iterator(){
curr_=nullptr;
}
template <typename T>
RecentList<T>::const_iterator::const_iterator(Node* p){
curr_=p;
}
template <typename T>
typename RecentList<T>::const_iterator RecentList<T>::const_iterator::operator++() const{
//++it
curr_ = curr_->next_;
return *this;
}
但是,当我尝试编译时,它给了我 42 个错误,例如:
“RecentList::const_iterator::operator++(int) const”,引用自:
最后是链接器错误。
还有模板东西存在的原因是列表类使用模板。当我不包含该语法时,Xcode 不喜欢它。
我应该在哪里解决问题?