关于C++编译期间类里的常量问题
#include "stdafx.h"#include<iostream>
using namespace std;
class StringStack
{
static const int size=100;
const string* stack[size];
int index;
public:
StringStack();
void push(const string*s);
const string* pop();
};
StringStack::StringStack():index(0)
{
memset(stack,0,size *sizeof(string*));
}
void StringStack::push(const string *s)
{
if(index<size)
stack[index++]=s;
}
const string*StringStack::pop()
{
if(index>0)
{
const string*rv=stack[--index];
stack[index]=0;
return rv;
}
return 0;
}
string iceCream[]={
"praline & cream",
"fudge ripple",
"jamocha alnond fudge",
"wild monutain blackberry",
"raspberry storbet",
"iemon swirl",
"rocky road",
"deep chocolate fudge"
};
const int iCsz=
sizeof iceCream/sizeof*iceCream;
int _tmain(int argc, _TCHAR* argv[])
{
StringStack ss;
for(int i=0;i<iCsz;i++)
ss.push(&iceCream[i]);
const string*cp;
while((cp=ss.pop())!=0)
cout <<(const string) *cp<<endl;
return 0;
}
stringstack\stringstack.cpp(62): error C2679: 二进制“<<”: 没有找到接受“std::basic_string<_Elem,_Traits,_Ax>”类型的右操作数的运算符(或没有可接受的转换)
1> with
追问:这样改程序可以调试通过,但输出的是地址值,程序目的要输出地址所指向的值,为什么用cout<<*p<<ednl;是不对的那?