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

parrylau parrylau 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
//利用栈实现的迷宫问题非递归解法.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)
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
parrylau
C++ 语言 65,214 成员 250,514 内容