Structs

Hi, I get a Error from the code of page 15 and 16 about structs, The code from the book works fine but when i try to make my one struct. And try to make the same program but with different variables and names it doesn't work. For Example I tried to change the name of the struct with the same code.

//Header File
typedef struct{
char firstInitial;
char middleInitial;
char lastInitial;
int employeeNumber;
int salary;
} EmployeeD; (Changed from EmployeeT)

cpp File

#include <iostream>
#include "employeestruct.h"
using namespace std;

int main ()
{
// create and populate an employee
EmployeeD anEmployee; ......

After this it gave my an error message:
error: expected ';' before 'anEmployee',
error: 'EmployeeD' was not declared in this scope and
error: 'anEmployee' was not declared in this scope

Can somebody explain this ?
kk,i kan..

#include <iostream>
#include "employeestruct.h"
using namespace std;


this should come before

typedef struct{
char firstInitial;
char middleInitial;
char lastInitial;
int employeeNumber;
int salary;
} EmployeeD; (Changed from EmployeeT)


followed by

int main ()
{
// create and populate an employee
EmployeeD anEmployee; ......
file (employeestruct.h) must go in the same folder as the cpp.. review
Yes, I did that already
Thanks marking the question as it ...
[b]// structtest.cpp[/b]

#include <iostream>
#include "employeestruct.h"

using namespace std;


int main ()
{
// create and populate an employee
EmployeeD anEmployee;

anEmployee.firstInitial = 'M';
anEmployee.middleInitial = 'R';
anEmployee.lastInitial = 'G';
anEmployee.employeeNumber = 42;
anEmployee.salary = 80000;

// output the values of an employee
cout << "Employee: " << anEmployee.firstInitial <<
anEmployee.middleInitial <<
anEmployee.lastInitial << endl;
cout << "Number: " << anEmployee.employeeNumber << endl;
cout << "Salary: $" << anEmployee.salary << endl;

return 0;
}

[b]// employeestruct.h[/b]

typedef struct{
char firstInitial;
char middleInitial;
char lastInitial;
int employeeNumber;
int salary;
} EmployeeD;


Well here you go.
mark Solved your question..
Last edited on
Topic archived. No new replies allowed.