奥流身份不明
Ostream unidentified?
本文关键字:身份 更新时间:2023-10-16
所以我有这个头文件,它有 2 个利用 ostream 的函数我正在尝试重载间接寻址运算符 (<<) 以允许我使用指向模板化列表节点的指针写入文件。
从 .h 文件这里是原型
void PrintForward(ostream &out);
void PrintBackward(ostream &out);
ostream& operator<< (ostream &out, List<t> const* p);
然后从.cpp文件
操作员过载功能
ostream& operator<< (ostream &out, ListNode::List const* p)
{
return out << *p;
}
前进打印功能
template <typename T>
void List<T>::PrintForward(ostream &out)
{
ListNode* lp = head;
while(lp != NULL)
{
out << *lp->value;
lp = lp -> next;
}
}
向后打印功能
template <typename T>
void List<T>::PrintBackward(ostream &out)
{
ListNode* lp = tail;
while(lp != NULL)
{
out << *lp;
lp = lp -> prev;
}
}
目前我得到的只是一个编译器错误,说
error C2061: syntax error : identifier 'ostream'
但我找不到它。在将所有函数切换到.cpp文件之前,我收到一个不同的错误,指出使用类模板需要模板参数列表。但它似乎已经消失了。
我可以在这段代码中看到很多问题:运算符<<的声明使用的是模板类 t,但没有此模板类的声明,例如
template<class t>
ostream& operator<< (ostream &out, List<t> const* p);
此外,这些函数的声明和定义在第二个参数中也不相等:
ostream& operator<< (ostream &out, List<t> const* p);
ostream& operator<< (ostream &out, ListNode::List const* p)
最后,我不知道从你的代码中你是否正在使用命名空间 std,如果不是,那么你必须在 ostream 类之前编写 std::,就像这样:
std::ostream& operator<< (std::ostream &out, List<t> const* p);
std::ostream& operator<< (std::ostream &out, ListNode::List const* p)
您尚未发布所有代码,但我注意到您没有使用 std 使 ostream 符合条件:
//.h
std::ostream& operator<< (std::ostream &out, List<t> const* p);
//.cpp
//...
// Either qualify with std, or bring it into scope by using namespace std...
相关文章:
- LibGit2 SSH身份验证失败
- 以非特权用户身份查询 NTFS 特殊文件的元数据?
- 为什么 WinInet 在通过 FQDN 连接时无法通过协商自动进行身份验证,但如果通过 IP 连接则成功?
- 如何通过NetHTTPClient在HTTPS中进行身份验证
- 临时对象有身份吗?
- 以管理员身份运行应用程序时,有没有办法获取非管理员用户名
- 处理身份验证弹出窗口在wxWebView
- Win7 C++ - 从以用户身份登录的服务启动可执行文件的问题
- 如何测试我的谷歌身份验证器实现?
- 通过 Boost 和 C++ 进行 SMTP 身份验证
- dopen():不以 root 身份运行时"failed to map segment from shared object"
- libtorrent是否支持带摘要身份验证的http web种子
- 将Windows身份验证与cpprestsdk一起使用
- OCCI:使用SSL钱包身份验证连接到OracleDB
- 为什么我不能使用外围设备进行身份验证
- 接收用户所属的所有成员身份组的 SID?
- 无法使用C++代码向MongoDB进行身份验证
- 模拟的 HTTP 身份验证仅在本地主机上工作
- 如何在 Linux 中通过 C/C++ 以其他用户身份创建文件?
- 以 7 位身份访问 8 位数据