I am beginning to teach myself C++ and have come across an error for which I believe is quite simple but not catching it. I created the following header file named EmployeeT.h
#ifndef EMPLOYEET_H_INCLUDED
#define EMPLOYEET_H_INCLUDED
typedef struct
{
char firstInitial;
char middleInitial;
char lastInitial;
int employeeNumber;
int salary;
} EmployeeT
#endif // EMPLOYEET_H_INCLUDED
with the main as
#include <iostream>
#inclide <Employee.h>
using namespace std;
int main()
{
EmployeeT anEmployee;
anEmployee.firstInitial = 'M';
anEmployee.middleInitial = 'R';
anEmployee.lastInitial = 'G';
anEmployee.employeeNumber = 42;
anEmployee.salary = 80000;
cout << "Employee: " << anEmployee.firstInitial <<
anEmployee.middleInitial <<
anEmployee.lastInitial << endl;
cout << "Number: " << anEmployee.employeeNumber << endl;
cout << "Salary: " << anEmployee.salary <<endl;
return 0;
}
You missed semicolon:
typedef struct
{
char firstInitial;
char middleInitial;
char lastInitial;
int employeeNumber;
int salary;
} EmployeeT;
//^^Must not miss this ;
Meanwhile:
#inclide <Employee.h>
//^^typo
should be:
#include "Employee.h"
Last point: you may initialize your struct as follows:
anEmployee = {'M','R','G',42, 80000};
//It will assign values to field in automatic way
If you are curious, you may also take a look at uniform initialization which is introduced since C++11.
In main don't you want to #include "EmployeeT.h" instead of #include <Employee.h>?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With