PDA

View Full Version : DO we Need to include headers if we are using static Library in Nested scenario?



blue_sky
19th September 2013, 14:24
If I am using members of a class which a Static lib,Then I must add header file of that class in my .cpp.
But, If that class is using some other libs, then should I include those other libs(class) header in my cpp file.

ex= my program
==============
need a class which in X.lib.
I am using only X class object in
my cpp.So I should include X class header
in my file.
But if X class in X.lib is using another lib Y.lib internally,
then should I include Y class definition in my CPP?
(I know Y.lib must be included in my project, but should Y.h should be included?)

anda_skoa
19th September 2013, 17:32
You only need to include headers for declarations that you are using.

So if you are using a class A, include the header where this class is declared.
If that class is internally using a class B, then you are not using that class hence you don't need to include the declaration of B.

This is totally independent of any form of linking. It is true for classes of the same project, for classes in static lbraries and for classes in dynamic libraries.
(and of course for functions, constants, etc)

Cheers,
_