Aya Ahmed
Aya Ahmed

Reputation: 3

"expression must have class type" error in C++

I got "expression must have class type" error while defining a method in a C++ struct. I do not know why.

The code:

struct qqueue {

    int ar[20000];
    int rear = 0;

    void add_end(int c) {
        ar[rear++] = c;
        
    }

    void add_front( int c) {
        if (rear < ar.sz - 1) {               // expression must have class type
            for (int i = rear; i > 0; i--)
                ar[i] = ar[i - 1];
            ar[0] = c;
            rear++;
        }
        else
            cout << " is Full";
    }
};

Upvotes: 0

Views: 106

Answers (1)

Raildex
Raildex

Reputation: 4737

ar.sz

does not work. ar is of type int[], which doesn't have any members. since you know the size at compile time, you may want to write 20000.

Since you are using cpp, I'd suggest using std::vector or std::array

Upvotes: 2

Related Questions