当前位置:我的异常网» C++ » 为啥会出现error C2146
为啥会出现error C2146
www.myexceptions.net 网友分享于:2013-10-19 浏览:71次
为什么会出现error C2146:
#include
#include
template
class SqStack
{
public:
void clear();
int getLength();
int getstackSize();
Status getTop(ElemType& e);
bool isEmpty();
SqStackoperator=(SqStackrightS);
Status pop(ElemType& e);
void push (ElemType& e);
SqStack();
virtual ~SqStack();
SqStack(const SqStack& otherS);
protected:
ElemType *base;
ElemType *top;
int stackSize;
};
template
void SqStack::clear()
{
base=top;
}
template
int SqStack::getLength()
{
return top-base;
}
template
int SqStack::getstackSize()
{
return SqStackSize;
}
template
Status SqStack::getTop(ElemType& e)
{
if(isEmpty())
return ERROR;
else
e=*(top-1);
return OK;
}
template
bool SqStack::isEmpty()
{
return (top==base?true:false);
}
template
SqStackSqStack::operator =(SqStack rightS)
{
int length=rights.getLength();
if(this!=&rightS)
{
if(stackSize
{
delect[] base;
base=new ElemType[right.stackSize];
assert(base!=0);
stackSize=rightS.stackSize;
}
for(int i=0;i
*(base+1)=*(rightS.base+i)
top=base+length();
}
return *this;
}
template
Status SqStack::pop(ElemType& e)
{
if(isEmpty())
return ERROR;
else
e=*--top;
return OK;
}
template
void SqStack::push(ElemType& e)
{
int length=top-base;
ElemType *newbase;
if(top-base>=stackSize)
{
newbase=new ElemType[stackSize+STACKINCREMENT];
assert(newbase!=0);
for(int j=0;j
*(newbase+j)=*(base+j);
delete []base;
stackSize+=STACKINCREMENT;
base=newbase;
top=base+length;
}
*top=e;
++top;
}
template
SqStack::SqStack()
{
base=new ElemType[STACK_MAX_SIZE];
assert(base!=0);
stackSize=STACK_MAX_SIZE;
top=base;
}
template
SqStack::~SqStack()
{
if(base)
delete []base;
stackSize=0;
top=base=NULL;
}
template
SqStack::SqStack(const SqStack& otherS)
{
int length;
base=new ElemType[otherS.stackSize];
assert(base!=0);
stackSize=otherS.stackSize;
for(int i=0;i
*(base+i)=*(otherS.base+i);
top=base+length;
}
总是出现这样的错误
ompiling...
q.cpp
f:\microsoft visual studio\myprojects\zhan\q.cpp(10) : error C2146: syntax error : missing ';' before identifier 'getTop'
f:\microsoft visual studio\myprojects\zhan\q.cpp(23) : see reference to class template instantiation 'SqStack' being compiled
f:\microsoft visual studio\myprojects\zhan\q.cpp(10) : error C2501: 'Status' : missing storage-class or type specifiers
f:\microsoft visual studio\myprojects\zhan\q.cpp(23) : see reference to class template instantiation 'SqStack' being compiled
f:\microsoft visual studio\myprojects\zhan\q.cpp(13) : error C2146: syntax error : missing ';' before identifier 'pop'
f:\microsoft visual studio\myprojects\zhan\q.cpp(23) : see reference to class template instantiation 'SqStack' being compiled
文章评论