不能在返回字符的类中调用函数

问题描述 投票:0回答:1

[当我尝试调用st.top()时出现错误,提示“明显调用的括号前的表达式必须具有(指针到)函数类型”)>

string infixToPostfix(string hasil)
{
    Stack st;
    string postfix = "";

    for (int i = 0; i < hasil.length(); i++)
    {
        if (hasil[i] == ' ')
        {
            continue;
        }
        else if (isOperator(hasil[i]))
        {
            while (st.isEmpty() && hasHigherPrecedence(st.top(), hasil[i])) // the error is here
            {
                postfix = postfix + st.top(); // and here
            }

        }
    }
}


class Stack {

    public:
    int top = -1;
    char array[MAX];

    bool isEmpty()
    {
        if (top == -1)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    bool isFull()
    {
        if (top == (MAX-1))
        {
            return true;
        }
        else
        {
            return false;
        } 
    }

    void push(char masuk)
    {

        if (isFull())
        {
            cout << "Expresi yang anda masukkan telah melebihi stack" << endl;
        }
        else
        {
            top++;
            array[top] = masuk;
        }
    }

    void pop()
    {
        if (isEmpty())
            {
                cout << "Stack sudah kosong!" << endl;
            }
            else
            {
                top--;
            }
    }

    char top()
    {
        if (isEmpty())
        {
            cout << "Stack kosong" << endl;
        }
        else
        {
            return array[top];
        }
    }

};

[当我尝试调用st.top()字符串infixToPostfix(string hasil)时出现错误,提示“明显的括号前的表达式必须具有(指针指向)函数类型”。 ...

c++ arrays function char call
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.