c++ - 在模板中声明友元函数时发出警告
问题描述
找不到我收到以下警告的原因:
simple_list.h:36:69: warning: friend declaration ‘std::ostream& operator<<(std::ostream&, const list<Elem>&)’ declares a non-template function [-Wnon-template-friend] 36 | friend std::ostream &operator<<(std::ostream &os, const list <); | ^ simple_list.h:36:69: note: (if this is not what you intended, make sure the function template has already been declared and add <> after the function name here)
我已经在头文件中声明了friend函数,如下所示
#include <iostream>
#include <limits>
template<typename Elem>
struct Link {
Link* succ;// successor (next) link
Elem val;// the value
};
template<typename Elem>
class list {
private:
unsigned int lsize;
Link<Elem>* first;
Link<Elem>* last; // one beyond the last link
public:
class iterator;
list();
list &operator=(const list &obj);
bool empty();
unsigned int size();
iterator begin();
iterator end();
iterator insert_after(iterator p, const Elem &v);
iterator erase_after(iterator p);
// void push_back(const Elem& v);
void push_front(const Elem &v);
// void pop_front();
// void pop_back();
Elem &front();
// Elem& back();
unsigned int max_size();
friend std::ostream &operator<<(std::ostream &os, const list <);
~list();
};
解决方案
推荐阅读
- excel - 根据多列条件将单元格从一个工作表复制到另一个工作表
- html - HTML/CSS - 将多个文本元素连接在一起
- apache - 如何重写 url 以使用 Apache 附加标头
- python-3.x - python 3 pandas数据帧的迭代以外的条件和技术
- java - 我们可以跳过 Java8 Streams
- sql - 使用索引进行 SQL Select 查询优化
- jquery - 如何使用 jQuery AJAX 过滤使匹配的项目变为粗体
- delphi - 使用delphi,我有一个dbgrid。我想当用户填写该行并发布它时,网格线是只读的
- spring - 如何定义具有许多 AND、OR 和 NOT 的不同阶段的弹簧轮廓?
- c++ - 如何在方法调用中显式引用对象?