Home > Net >  Redefinition and fail to use ifned/def/endif
Redefinition and fail to use ifned/def/endif

Time:05-30

I'm trying to make a program that follows the following UML diagram My UML diagram

I've divided each class into its respective header and cpp. However, while doing some tests on it I found plenty of messages of redefinition so I tried using ifndef, def and endif however as you can see in this image (my commission worker header) it seems as if I wasn't including the employee header at all ComisionWorker header

I'm using Visual Studio Code if that's relevant (Also, I doubled checked my file's name so that's not the problem)

CodePudding user response:

You include the header file for the Employee Class by using the preprocessor directive #include "HEADERNAME.h/hpp" In your case: #include "Employee.h", if your header file is called like that.

You used so called "Include/Header guards" which are used to prevent multiple header inclusions. Those should be put in the respective header file, not in other header files that include it. Alternatively you can use #pragma once. It's non-standard, but should be widely supported.

For your strings you wanna address the namespace std as such: std::string

  • Related