How to avoid compilation errors with multiple header files in C++?

  • Context: C/C++ 
  • Thread starter Thread starter Sam Groves
  • Start date Start date
  • Tags Tags
    C++
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 3K views
Sam Groves
Messages
11
Reaction score
0
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?
 
Physics news on Phys.org
You can use the pragma once idiom or some of the other methods shown on that page.
 
Reply
  • Like
Likes   Reactions: FactChecker