[英]error: ‘’ was not declared in this scope [C++]
cpp and
.h`文件进行堆栈,当我尝试一起编译时,出现类似以下错误
error: 'top_index' was not declared in...
在两个函数bool empty()
和int size()
。
我的.cpp
代码是:
#include "char_stack.h"
char_stack::char_stack(){
top_index = -1;
}
void char_stack::push(char item){
top_index = top_index + 1;
A[top_index] = item;
}
char char_stack::pop(){
top_index = top_index - 1;
return A[top_index + 1];
}
char char_stack::top(){
return A[top_index];
}
bool empty(){
return top_index == -1;
}
int size(){
return top_index + 1;
}
我的.h
文件代码是:
class char_stack
{
public:
char_stack();
void push( char item );
char pop();
char top();
bool empty();
int size();
private:
static const int capacity = 250000;
int A[capacity];
int top_index;
};
请有人帮助我我做错了什么? 我什至把include放在cpp上并引起问题:(
bool empty(){
return top_index == -1;
}
int size(){
return top_index + 1;
}
您忘记声明这些函数是类方法,就像声明的所有其他类方法一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.