C++ header files and classes

  • Thread starter Sam Groves
  • Start date
  • Tags
    C++
  • #1
Sam Groves
11
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?
 
Technology news on Phys.org
  • #2
You can use the pragma once idiom or some of the other methods shown on that page.
 
  • Like
Likes FactChecker
  • #3
From a C standpoint, I would use #ifndef <Some variable defined in the header you are trying to include>.
 

Similar threads

  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
2
Views
244
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
3
Replies
81
Views
5K
  • Programming and Computer Science
Replies
6
Views
811
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
7
Views
2K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
2
Views
142
  • Programming and Computer Science
Replies
5
Views
749
Back
Top