Q:I wonder since I already declare mergeList() in the header file, shouldn't it be complied before implementation of sortList() (which uses mergeList)?
In C, when header file is included (ie:#include "sortList.h"
), it is as though the #include ...
line is replaced with the entire code of the specified .h
file is inserted at that point. In essence, the content of the .h
file becomes part of the .c
file (or, .cpp
file) being compiled.
This is true for each .c
file (or, .cpp
file) which includes any specific .h
file.
Hence, in the above question, "...shouldn't it be complied before implementation of sortList()"
, the answer is 'no'. Not 'before', but rather 'with'. Specifically, if prototypes sortList()
and mergeList()
exist in sortlist.h
, for it is customary for both sortList.cpp and mergeList.cpp to #include "sortList.h"
". Thus, the code of sortList.h
becomes part of both these files.
Q:Or shall I declare mergeList() again in sortList.cpp?
No, just make sure that sortList.h
is included in sortList.cpp.