0

Okay, so I have narrowed the problem having to do with the #ifndef and/or the #define keywords.

I have 2 other .h files and the only difference between the ones with no errors and the ones without is the syntax highlighting on the #ifndef EMPLOYEE_H and the #define EMPLOYEE_H is swapped on the file with errors.

I'm not sure what that means though (I am using Visual Studio), but it's causing all of my other defined statements to go white like they are being included in some.

I'm not sure what's wrong!

Here is my code:

//Specification file for the Employee Class
#ifndef EMPLOYEE_H
#define EMPLOYEE_H

#include <string>

using namespace std;


class Employee

{

protected:
//Employee name
string name;
//Required Training hours
string emNum;
//Completed training hours
string hireDate;


public:
//Default Constructor
Employee()
{
    name = " ";
    emNum = " ";
    hireDate = " ";
}

//Constructor
Employee(string aName, string aNumber, string aDate)
{
    name = aName;
    emNum = aNumber;
    hireDate = aDate;
}

//mutators
void setName(string empName) { name = empName; }
void setEmployeeNumber(string empNumber) { emNum = empNumber; }
void setHireDate(string date) { hireDate = date; }

//accessors
string getName() const { return name; }
string getEmployeeNumber() const { return emNum; }
string getHireDate() const { return hireDate; }


#endif



};

My Errors are:

Error 1 error C2059: syntax error : '}'

Error 2 error C2143: syntax error : missing ';' before '}'

4 IntelliSense: expected a declaration

Blockquote

Also the error is highlighting the }; at the very end.

Community
  • 1
  • 1
Zelf
  • 21
  • 1
  • 4

1 Answers1

3

The problem is with the the #endif directive which is located inside the definition of the class (before the }; code), thus a second inclusion of this header file will only include the }; code causing the errors you got.

BTW, instead of using the #ifndef pattern you can simply use #pragma once at the beginning of your file which has the same effect. You can read more about pragma once vs. using include guards in here.

Community
  • 1
  • 1
Amnon Shochot
  • 7,646
  • 3
  • 22
  • 27
  • Thank You so much!! I put it on the outside and the classes work just fine now thanks again! – Zelf Apr 11 '15 at 03:02