c++11 - 错误 C2679 二进制“<<”:未找到采用“T”类型右侧操作数的运算符(或没有可接受的转换)
问题描述
我的模板类中的朋友功能有问题。出于某种原因,它不喜欢我试图在运算符重载友元函数中使用类型为 T 的变量这一事实。
#include <iostream>
#include <fstream>
#include <string>
template <typename T>
class LL
{
struct Node
{
T mData;
Node *mNext;
Node();
Node(T data);
};
private:
Node *mHead, *mTail;
int mCount;
public:
LL();
~LL();
bool insert(T data);
bool isExist(T data);
bool remove(T data);
void showLinkedList();
void clear();
int getCount() const;
bool isEmpty();
friend std::ofstream& operator<<(std::ofstream& output, const LL& obj)
{
Node* tmp;
if (obj.mHead != NULL)
{
tmp = obj.mHead;
while (tmp != NULL)
{
output << tmp->mData << std::endl; // "tmp->mData is causing the error
tmp = tmp->mNext;
}
}
return output;
}
};
这是一个链表类,我需要友元函数运算符重载才能基本上允许我将任何特定的对象列表输出到文本文件中。我希望有人可以帮助我。
解决方案
推荐阅读
- pine-script - 如何仅计算筛选脚本上的最新蜡烛
- javascript - 事件侦听器“消息”,基于事件名称在 angularJs、javascript 中使用 promise 进行 API 调用
- javascript - SignalR 通过 IProgress
从 js 客户端到集线器 - javascript - javascript正则表达式如何提取url子字符串
- amazon-web-services - 部署 aws lambda 函数时无法访问我的注册表中的 ecr 存储库
- performance - 使用 MPI_PACK() 的优势
- ssh - 在所有 openshift pod 上安装 python 库
- matlab - 使用 Matlab 通过全局拟合找出基础数据集的相对贡献?
- r - 从具有不同行数的单独数据框创建箱线图
- tcl - 为什么只有 PUTNOW 可以在 eggdrop tcl 中使用绑定时间或绑定 cron?