Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Velpus Captiosus

Well-Known Coder
I have a class Stack with a header file Stack.h which uses up another class with a header file Activity.h

I have a third class ActivityManager which uses up both the Stack and the Activity class.If I run the program and add in both Activity.h and Stack.h to the #include list I get a compilation error:Activity.h is defined 2 times in the script.How do I solve this issue?
 
The issue might have been encountered due to multiple inclusion of the header file Activity.h.

This is a common problem in C++ when a header file is included in multiple files, causing the same declarations.

You can include guards in your header files. Include guards are preprocessor directives that prevent a header file from being included multiple times in the same translation unit.
 
The solution suggested by @MilesWeb is the way to go. Write your activity.h like this

C:
#ifndef ACTIVITY_H
#define ACTIVITY_H
// Actual contents of header file
#endif

This way when you include it a second time, it falls right through. This is how all include files in standard libraries work.
 

New Threads

Buy us a coffee!

Back
Top Bottom