0
#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;
}

I'm taking prototype for 'int IntStack::isEmpty()' does not match any in class 'IntStack' error in my compiler also it says candidate is:bool IntStack::isEmpty()

  • i'm using Dev-C++ 5.11

  • I just started coding so the other functions is empty.

  • 1
    You forgot the return type. – tkausl Mar 04 '19 at 10:15
  • Why are you using `1` and `0` for `true` and `false`? – Some programmer dude Mar 04 '19 at 10:16
  • 2
    I also recommend you go back to your book or tutorial and read more about pointers and how to do dynamic allocation. When you do `stackArray[stackSize];` in your constructor, that won't work (and in fact will lead to [*undefined behavior*](https://en.wikipedia.org/wiki/Undefined_behavior) as you dereference an uninitialized pointer). If you don't have any books, then I recommend [you get a couple of good ones](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list/388282#388282). – Some programmer dude Mar 04 '19 at 10:19
  • I'll change it later but for now i need to know which one is true @Someprogrammerdude and thanks for warning btw – Sefa Kalkan Mar 04 '19 at 10:41

2 Answers2

1

this should do you should specify the return type too in the definition

 bool  IntStack::isEmpty(){
 // to optimize the code you can do
    return top==0;
}
Spinkoo
  • 2,080
  • 1
  • 7
  • 23
1

You have forgotten the return type for the function prototype.

bool
IntStack::isEmpty(){
    if(top == 0)
      return 1;
    else
      return 0;
}
Destructor
  • 523
  • 1
  • 3
  • 13