ITPub博客

首页 > 应用开发 > > c++ 输出单链表元素

c++ 输出单链表元素

作者:gamebus 时间:2019-08-15 09:46:21 0 删除 编辑

//函数声明部分

friend ostream& operator<<<>(ostream&,SinglyList<T>&);    //输出单链表所有元素

//函数定义

template

ostream& operator<< (ostream &out,SinglyList &list)

{

out<<"(";

for(Node *next=list.head->next; next != NULL; next = next->next)

{

out<data;

if(next->next != NULL)

out<<",";

}

out<<")\n";

return out;

}

g++ 编译时报错:

SinglyList.h:64:55: 错误:模板标识符‘operator<< ’出现在基本模板的声明中

ostream& operator<< (ostream &out,SinglyList &list)

SinglyList.h:20:19: 错误:‘std::ostream& operator<<(std::ostream&, SinglyList&)’的模板标识符‘operator<< ’不匹配任何模板声明

friend ostream& operator<< (ostream&,SinglyList&);    //输出单链表所有元素

 

这是我在书上看到的代码,在我的环境中编译报错。

首先对于“operator<<<>”这部分中的<>不明白代表什么意思?

先谢了。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4687/viewspace-3161293/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-07-10

  • 博文量
    155
  • 访问量
    13186