C++ Expression must have pointer-to-object type

You probably meant:

c_info[i].hoursWorked;

since c_info is an array, by doing c_info[i] you'll access the i-th instance (object) of Employee class in c_info array, and then obtain hoursWorked through . operator.

Now you can clearly see that your variant simply doesn't make sense, as hoursWorked is just an integral type and not an array, and therefore you cannot apply [] operator to it.


c_info is a pointer to an Employee. You can assign a single allocated object to such a pointer or, in your case, multiple ones (new with the array syntax). So it points to an array of Employees.

You dereferenced that pointer. Since it points to an array of (multiple) Employees, it also points to the first entry. Then you access an integer member variable, which is still possible. But then you try to use the array subscript operator ([]) on an integer value, which is not possible.

You probably meant to access the member variable of the i-th entry of your allocated array. So you have to turn this around: First use the array subscript operator, then access the member on that particular Employee.

c_info[i] in low-level words means: Take the pointer c_info, add i times the size of the type it points to (so it points to the i-th entry) and dereference that address. This means, that c_info[i] actually is the Employee at the i-th index (but not a pointer).

Then you want to access a member of that employee. If it still was a pointer, you would have to use the arrow operator, but since you used the array subscript operator ([i]), you already have dereferenced it, you the point operator is the correct one:

cin >> c_info[i].hoursWorked;