MentalSentinel
08-14-2005, 11:53 AM
Hey.
I'm currently in my C++ learning phase. (again..)
I made a small program that lets you add an employee or call upon all employees and list their employee number, salary and the amount of years the employee has been.. employed.
But, I'm getting two errors on line 54 and 55, saying that what's left of .salaris and .jaarInDienst must be class/struct/union typed.
Here is the entire error message (using Visual C++ 6.0):
(54) : error C2228: left of '.salaris' must have struct/class/union type.
And the same message of line 55.
This is my code:
#include <iostream>
using namespace std;
class Werknemer
{
public:
int jaarInDienst;
int salaris;
Werknemer(int salarisWerknemer, int jaarInDienstWerknemer);
};
Werknemer::Werknemer(int salarisWerknemer, int jaarInDienstWerknemer)
{
salaris = salarisWerknemer;
jaarInDienst = jaarInDienstWerknemer;
cout << "Employee added!";
}
int main()
{
int restart;
int action;
Werknemer *werknemerarray[3];
int i = 0;
while(true)
{
cout << "What would you like to do?";
cout << "\n" << "(1) Add an employee.";
cout << endl << "(2) List all employees.\n\n";
cin >> action;
if(action == 1)
{
int employeesalary;
int jaarInDienst;
cout << "\n\nWelcome to the add-an-employee section!\n";
cout << "Please enter an employee salary. ";
cin >> employeesalary;
cout << "\nPlease enter the amount of years this employee has served. ";
cin >> jaarInDienst;
cout << "\nThank you. Processing your request....\n";
werknemerarray[i] = new Werknemer(employeesalary, jaarInDienst);
i++;
}
if (action == 2)
{
int tempi = 0;
cout << "\n Listing all employees..";
while(tempi < i)
{
cout << "Employee number: " << tempi;
cout << "\nEmployee salary: " << werknemerarray[tempi]->salaris;
cout << "\nYears served: " << werknemerarray[tempi]->jaarInDienst;
cout << endl << endl;
tempi++;
}
}
cout << "Do you wish to restart (1/0)?\n";
cin >> restart;
if(restart == 0)
break;
}
return 0;
}
Can anyone please tell me how to fix this and what this means?
Anyway, forgive my lack of comment and partly Dutch and English.
Cheers, MentalSentinel.
I'm currently in my C++ learning phase. (again..)
I made a small program that lets you add an employee or call upon all employees and list their employee number, salary and the amount of years the employee has been.. employed.
But, I'm getting two errors on line 54 and 55, saying that what's left of .salaris and .jaarInDienst must be class/struct/union typed.
Here is the entire error message (using Visual C++ 6.0):
(54) : error C2228: left of '.salaris' must have struct/class/union type.
And the same message of line 55.
This is my code:
#include <iostream>
using namespace std;
class Werknemer
{
public:
int jaarInDienst;
int salaris;
Werknemer(int salarisWerknemer, int jaarInDienstWerknemer);
};
Werknemer::Werknemer(int salarisWerknemer, int jaarInDienstWerknemer)
{
salaris = salarisWerknemer;
jaarInDienst = jaarInDienstWerknemer;
cout << "Employee added!";
}
int main()
{
int restart;
int action;
Werknemer *werknemerarray[3];
int i = 0;
while(true)
{
cout << "What would you like to do?";
cout << "\n" << "(1) Add an employee.";
cout << endl << "(2) List all employees.\n\n";
cin >> action;
if(action == 1)
{
int employeesalary;
int jaarInDienst;
cout << "\n\nWelcome to the add-an-employee section!\n";
cout << "Please enter an employee salary. ";
cin >> employeesalary;
cout << "\nPlease enter the amount of years this employee has served. ";
cin >> jaarInDienst;
cout << "\nThank you. Processing your request....\n";
werknemerarray[i] = new Werknemer(employeesalary, jaarInDienst);
i++;
}
if (action == 2)
{
int tempi = 0;
cout << "\n Listing all employees..";
while(tempi < i)
{
cout << "Employee number: " << tempi;
cout << "\nEmployee salary: " << werknemerarray[tempi]->salaris;
cout << "\nYears served: " << werknemerarray[tempi]->jaarInDienst;
cout << endl << endl;
tempi++;
}
}
cout << "Do you wish to restart (1/0)?\n";
cin >> restart;
if(restart == 0)
break;
}
return 0;
}
Can anyone please tell me how to fix this and what this means?
Anyway, forgive my lack of comment and partly Dutch and English.
Cheers, MentalSentinel.