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


dear stackoverflow helpfull community,

this first program using pointer structure, , despite lots of research, not able find looking for, please forgive me if has been responded to.

i have project school have define structures use pointers array store data. in loop, error "expression must have pointer-to-object type"

for (int = 0; < nbclerk; i++)             {                 cout<<"number of hours: ";                 cin>>c_info->hoursworked[i];             }             break; 

here's whole code. thank help

#include <iostream> #include <string> #include <iomanip> using namespace std;  //structure defining employee struct employee {     int hoursworked;     int hourrate;     double overtime;     string name;     int empid; };  //function collecting , calculating info void employeeinfo(int nboperator, int nbclerk){      char classofemployee;      employee *c_info;     c_info = new (nothrow) employee[nbclerk];      employee *o_info;     o_info = new (nothrow) employee[nboperator];      cout<<"select class of employee (c=clerk, o=operator)";     cin>>classofemployee;      switch (tolower(classofemployee))     {     case 'c':          (int = 0; < nbclerk; i++)         {             cout<<"number of hours: ";             cin>>c_info->hoursworked[i];         }         break;     } }  int main(){     int nb1,nb2;     cout<<"nb employee , nb of nb of operator: ";     cin>>nb1>>nb2;     nbemployee(nb1, nb2);     system("pause"); } 

you meant:

c_info[i].hoursworked; 

since c_info array, doing c_info[i] you'll access i-th instance (object) of employee class in c_info array, , obtain hoursworked through . operator.

now can see variant doesn't make sense, hoursworked integral type , not array, , therefore cannot apply [] operator it.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

node.js - Bad Request - node js ajax post -

uitableview - Create and use custom prototype table cells in xamarin ios using storyboard -