int/char stack issue

I am getting an error stating 'error: cannot convert 'char*' to 'int*' in assignment
stackArray = new char[size];'


I can't seem to figure out what the issue is here,
^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  #include <iostream>
using namespace std;

class CharStack
{
    private:
        int size;
        int top;
        int *stackArray;

    public:
        CharStack(int newSize)
        {
            size = newSize;
            stackArray = new char[size];
            top = -1;
        }

        void push(char newLetter){ stackArray[++top] = newLetter; }

        char pop() { return stackArray[top--]; }

        char peek() {return stackArray[top]; }

        bool isEmpty() {return (top == -1); }

        bool isFull() {return (top == size - 1); }
};
int main()
{
    char a[] = {'h','e','l','l','o',' ','w','o','r','l','d','!'};

    CharStack reverse(12);

    for (int i = 0; i < 12; i++)
        reverse.push(a[i]);

    while (reverse.isEmpty())
        cout << reverse.pop();


}
You have declared stackArray as an int* int *stackArray;
but then you try to assign a char* to it stackArray = new char[size];
Last edited on
Topic archived. No new replies allowed.