类别未被识别
Class not being recognised
本文关键字:识别 更新时间:2023-10-16
这是我的代码:
template <class a, class b>
class LinkedListIter{
public:
LinkedListIter(b* iterable){
this->iterable = iterable;
this->head = this->iterable->head;
this->curr = this->iterable->curr;
this->iter_pos = 0;
};
void operator++(int dummy){
this->iter_pos++;
};
friend std::ostream& operator<< (std::ostream& o, LinkedListIter const& lli);
private:
a* head;
a* curr;
b* iterable;
int iter_pos; //The current position if the iterator
};
std::ostream& operator<< (std::ostream& o, LinkedListIter const& lli){
return o << lli.get(lli.iter_pos);
}
在我声明std::ostream& operator<< (std::ostream& o, LinkedListIter const& lli)
的那一行,我得到了一个错误,说LinkedListIter没有命名类型。为什么会这样?
LinkedListIter
是一个类模板,而不是一个类。所以你的操作员也需要成为一个模板。
template<typename a, typename b>
std::ostream& operator<< (std::ostream& o, LinkedListIter<a,b> const & lli){
...
#include <iostream>
template <class a, class b>
class LinkedListIter;
template <class a, class b>
std::ostream& operator<< (std::ostream& o, LinkedListIter<a, b> const& lli);
template <class a, class b>
class LinkedListIter{
public:
LinkedListIter(b* iterable) {
this->iterable = iterable;
this->head = this->iterable->head;
this->curr = this->iterable->curr;
this->iter_pos = 0;
};
void operator++(int dummy) {
this->iter_pos++;
};
friend std::ostream& operator<< <a, b> (std::ostream& o, LinkedListIter const& lli);
private:
a* head;
a* curr;
b* iterable;
int iter_pos; //The current position if the iterator
};
template <class a, class b>
std::ostream& operator<< (std::ostream& o, LinkedListIter<a, b> const& lli) {
return o << lli.get(lli.iter_pos);
}
这段代码可以编译得很好,希望得到帮助。
相关文章:
- 提升 ASIO 无法识别计时器对象
- 从udp接收帧对于人脸识别来说太慢
- 模板类无法识别友元运算符
- std::visit无法识别类型
- 无法识别模板功能
- 我有两个类需要在同一 cpp 文件中相互引用,但第一个类无法识别第二个类类型的对象
- 如何在LLVM中dyn_cast以识别StoreInst?
- 从不同的附加依赖项中识别等同命名的函数
- C++出现控制台错误.我无法识别源代码的问题
- VSCode IntelliSense无法识别SDL框架的SDL_image扩展库
- Qt:"Q3DScatter"即使包含在内也无法识别
- 使用指针的类识别
- 如何静态识别动态堆分配?
- 为什么C++无法识别我的对象实例化?
- C++ 无法识别创建进程'telnet'
- 识别 2D 矢量C++中的位置
- 如何识别项目是 QT 中的文件还是文件夹
- ESP32 无法识别任何设备已连接到其接入点
- 无法识别 Mac c++ 文件系统库
- 识别数组中的重复元素?