0

I have a class called Restaurant that contains an Employee member. Now Employee is a friend class of Restaurant. When I try to compile this I get errors on the Employee mCurrentEmployee saying that its missing type specifier - int assumed. Why does the compiler get mad at me for this? Any ideas on how I can fix it? Thanks.

#pragma once
#include "employee.h"
class Restaurant{
    friend class Employee;

private:
    Employee mCurrentEmployee;

};

-

#pragma once
#include "restaurant.h"
class Employee {

}
Evan Nudd
  • 216
  • 2
  • 10
  • If a class contained within class why do you need to make it as friend? – Steephen Apr 23 '15 at 00:23
  • I'm guessing you have each header including the other – Praetorian Apr 23 '15 at 00:24
  • Both of these are in different files, Employee has some classes inheriting from it. I need to be able to get those children of Employee to be able to access certain data from Restaurant. and Restaurant needs to be able to call some functions of Employee – Evan Nudd Apr 23 '15 at 00:24
  • yes i do have each header including the other – Evan Nudd Apr 23 '15 at 00:24
  • So *employee.h* needs to be included before the definition of `Restaurant` and *restaurant.h* needs to be included before the definition of `Employee`, see a problem with that? Why does an `Employee` need to be a `friend` of a `Restaurant`, or vice versa? You should probably rethink your design. – Praetorian Apr 23 '15 at 00:30
  • You have a circular dependency with two header files including each other http://stackoverflow.com/questions/625799/resolve-circular-dependencies-in-c – Paul Renton Apr 23 '15 at 00:30

1 Answers1

2

If you remove the include of "restaurant.h" from employee that should resolve the friend issue (you may need to use forward declarations to get the code to compile but it's impossible to say for certain given the minimal code you've shown us).

That said you should ask yourself why an employee needs to be a friend of restaurant in the first place.

Mark B
  • 95,107
  • 10
  • 109
  • 188