3

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;
}
4

2 回答 2

9

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.

于 2013-06-01T02:07:18.243 回答
4

In main don't you want to #include "EmployeeT.h" instead of #include <Employee.h>?

于 2013-06-01T02:07:11.973 回答