哪位高手帮忙看下,怎么会有错呀?

parrylau 2007-05-24 09:08:31
//利用栈实现的迷宫问题非递归解法.cpp
#include <iostream>
#include <iomanip>
using namespace std;
//Stack.h Stack by chain
#ifndef CALCULATOR_HEAD
#define CALCULATOR_HEAD
#include <iostream>
using namespace std;
#endif

struct items
{//栈中三元组结构
int x,y,dir;
};
//////////////////////////////////////////////////////////////////////////
template <class Type>
class Stack; //声明
//////////////////////////////////////////////////////////////////////////
// define stack by chain...
template<class Type>
class StackNode
{// Stack-node by chain
friend Stack<Type>;
private:
Type Data;
StackNode<Type> * link;
StackNode(Type d,StackNode<Type> *l=NULL):Data(d),link(l)
{
}
public:

};
template <class Type>
class Stack
{// Stack by chain
friend ofstream & operator << (ofstream & Out,Stack<Type> StkObj)
{
return Out;
}
private:
StackNode<Type>* top;
public:
Stack():top(NULL) { } //构造函数 ,construct
~Stack();//distruct
bool IsEmpty();//judge whether is a empty stack
void MakeEmpty();//clear stack...
void Push(const Type&item);//压栈
Type Pop();//出栈
Type GetTop();//得栈头结点值
};

////////////////////the member function of class Stack<Type>//////////////////////////////////////////////////////
template <class Type>
bool Stack<Type>::IsEmpty()
{//是空链表栈吗?
return this->top==NULL;
}
template <class Type>
Stack<Type>::~Stack()
{
if (IsEmpty())
return ;
MakeEmpty();
return ;
}
template <class Type>
void Stack<Type>::MakeEmpty()
{//make the chain-stack emty
StackNode<Type> *pTemp=NULL;
if (IsEmpty())
return ;
while (top)
{
pTemp=top->link;
delete top;
top=pTemp;
}
return ;
}
template <class Type>
void Stack<Type>::Push(const Type&item)
{//压栈...
top=new StackNode<Type>(item,top);
return ;
}
template <class Type>
Type Stack<Type>::Pop()
{
StackNode<Type> *pTemp=NULL;
Type RetValue;

pTemp=top;
top=top->link;
RetValue=pTemp->Data;
delete pTemp;
return RetValue;
}
template <class Type>
Type Stack<Type>:: GetTop()
{
return top->Data;
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////
//

void main(void)
{
Stack<float> StkObjMaze;//设置工作栈

cout<<StkObjMaze;
}



编译器提示: error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class Stack<struct items>' (or there is no acceptable conversion)
...全文
181 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
systemthink 2007-05-31
  • 打赏
  • 举报
回复
自己高
granterfwj 2007-05-24
  • 打赏
  • 举报
回复
friend ofstream & operator << (ofstream & Out,Stack<Type> StkObj)
中ofstream 改为ostream 就可以了
F是多的
VCLIFE 2007-05-24
  • 打赏
  • 举报
回复
同意楼上
parrylau 2007-05-24
  • 打赏
  • 举报
回复
friend ofstream & operator <<(ofstream & ,Stack<items> );是在类里定义的一个友元函数

64,637

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧