c_info is a pointer to an Employee. You can assign one selected object to this pointer, or, in your case, several ( new with array syntax). Thus, he points to an array of employees.
You dereferenced this pointer. Since it points to an array of (several) employees, it also points to the first record. Then you access the integer member variable, which is still possible. But then you try to use the array index operator ( [] ) for an integer value, which is not possible.
You probably wanted to access the member variable of the i th record of your allocated array. So you need to rotate this: first use the array index operator, then refer to the member of that particular employee.
c_info[i] in low-level words means: take the pointer c_info , add i times the size of the specified type (so that it points to the i record) and dereference this address, This means that c_info[i] actually an Employee in the i th index (but not in the index).
Then you want to access the member of this employee. If it was still a pointer, you would need to use the arrow operator, but since you used the array index operator ( [i] ), you already dereferenced it, then the point operator is correct:
cin >> c_info[i].hoursWorked;
source share