user3473771
user3473771

Reputation: 1

Expression must have class type when using an array

I have a class for dealing with arrays and I am trying to check if it is empty. I keep getting the error "expression must have a class type."

This is my code:

int main ()
{
    Array ar1();
    bool isEmpty();
    cout << "The array is empty " << ar1.isEmpty();
}

What is wrong with it?

Upvotes: 0

Views: 1799

Answers (1)

4pie0
4pie0

Reputation: 29724

If you want to declare an array of Array elements write:

Array ar1[10];  // or other constant expression in [] as size specifier

This

Array ar1();

declares the function with name ar1 taking void and returning Array. Function is not a class thus "expression must have a class type" error when writing ar1.isEmpty().

Probably you want an array of some other elements then Array which is just mistake. This is how to declare an array named array of 10 ints:

int array[10];

Upvotes: 1

Related Questions