首页 > 解决方案 > 我正在使用 Prototype does not match in any class error in c++

问题描述

#include <iostream>

using namespace std;

#define MAX 100;

class IntStack{
private: 
    int *stackArray;
    int stackSize;
    int top;
public:
    IntStack();
    bool isEmpty();
    bool isFull();
    void push();
    void pop();
    void displayStack();
    void displayTopElement();
    int test();
};

IntStack::IntStack(){
    stackSize=MAX;
    stackArray[stackSize];
    top = 0;
}
IntStack::isEmpty(){
    if(top == 0)
      return 1;
    else
      return 0;
}

int main(){
   IntStack intStack;
   return 0;
}

我正在为 'int IntStack::isEmpty()' 的原型在我的编译器中与类 'IntStack' 中的任何错误不匹配,它还说候选是:bool IntStack::isEmpty()

标签: c++stack

解决方案


这应该做你应该在定义中指定返回类型

 bool  IntStack::isEmpty(){
 // to optimize the code you can do
    return top==0;
}

推荐阅读