关于模板的入门级问题
以下是代码
我用模板定义了一个栈,栈中用来存放字符串,但是为什么不能弹出啊
请高手帮我看下
///////////////////////////////////
#include "stdio.h"
#include <iostream>
using namespace std;
template <class Item>
class STACK
{
private:
Item* s;
size_t N;
public:
STACK(int i)
{
s=new Item[i];
N=0;
}
int empty() const
{
return N==0;
}
void push(Item item)
{
s[N++]=item;
}
Item pop()
{
return s[N--];
}
void Print()
{
int i=N;
for(i;i>0;i--)
{
cout<<"N:"<<i<<endl<<s[i]<<"----- "<<endl;
}
}
};
int main()
{
STACK<char*> stack(10);//按照我得理解,char*就是char[] 为什么换成char[]不行呢?
char hi[]="hi";
stack.push(hi);
stack.push("baby");
char* res=new char[20];
cout<<stack.pop();//这句出错!因为字符串不能正确的返回,改怎么做?
getchar();
}