hello everyone, I have some question about header files(I'm talking about c, but I think it will be the same for c++), let's assume I have some my_ADT.c file (inside I have implementation of the functions and actual struct) and also my_ADT.h inside I have pointer for my struct
Question: if I use ADT Set for implementation my_ADT do I need to include set.h to both files my_ADT.h and my_ADT.c or including only to my_ADT.h will be sufficient (inside my_ADT.c I have #include "my_ADT.h") thanks in advance
views:
60answers:
3
                +1 
                A: 
                
                
              
            If my_ADT.h is included in the my_ADT.c file, then you should include set.h only in my_ADT.h.
                  rhino
                   2010-10-02 17:11:27
                
              
                +3 
                A: 
                
                
              
            There are 3 scenarios
- set.his needed ONLY in- my_ADT.h
- set.his needed ONLY in- my_ADT.c
- set.his needed in both- my_ADT.hand- my_ADT.c
- set.his not needed at all :-)
For scenario 3) add the #include "set.h" to the file my_ADT.h, document that fact, and #include "my_ADT.h" in my_ADT.c (with proper include guards, you lose nothing by including set.h also to the C file).
For scenario 2) include set.h only in my_ADT.c
For scenario 1) include set.h only in my_ADT.h
                  pmg
                   2010-10-02 17:40:39
                
              
                
                A: 
                
                
              
            In addiction to pmg answer you must know that a good way of avoiding #include problem is to surround all header file with a precomplier instruction that check if the .h file has been already included.
#ifndef __my_ADT_header
#define __my_ADT_header
/*
 * your header declaration here
 */
#endif
this prevent error caused by multiple header inclusion
hope this helps
                  ArtoAle
                   2010-10-04 00:59:13