亲爱的 stackoverflow 有用的社区,
这是我第一个使用带有结构的指针的程序,尽管进行了大量研究,但我还是找不到我要找的东西。如果这已经得到回应,请原谅我。
我有一个学校项目,我必须定义结构而不是使用指针数组来存储数据。在这个循环中,我收到以下错误:
表达式必须具有指向对象的类型
for (int i = 0; i < nbClerk; i++)
{
cout<<"Number of hours: ";
cin>>c_info->hoursWorked[i];
}
break;
这是整个代码。非常感谢您的帮助
#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 and 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 the class of employee (C=Clerk, O=Operator)";
cin>>classOfEmployee;
switch (tolower(classOfEmployee))
{
case 'c':
for (int i = 0; i < nbClerk; i++)
{
cout<<"Number of hours: ";
cin>>c_info->hoursWorked[i];
}
break;
}
}
int main(){
int nb1,nb2;
cout<<"Nb Employee and nb of nb of operator: ";
cin>>nb1>>nb2;
nbEmployee(nb1, nb2);
system("pause");
}