繁体   English   中英

错误:在此范围内未声明“ [C ++]

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM