How does #include work in C ++?

If the library is included in the class header and then this header is included in another class, do I need to include the library again?

For instance:

#ifndef A_H
#define A_H

#include<someLibrary.h>

class A{
  ...
}

#endif

Then another class includes the heading Ah

#include<A.h>   //include class A
class B{
   ...
}

Do I need to include "someLibrary.h" in class B?

+4
source share
3 answers

No, they #includeare transitive.

, someLibrary, . , " ", . , #include , . .

+5

, , ( , ).

C/++ GNU cpp.

foo.cc, . g++ -Wall -C -E foo.cc ( )

(, 200KLOC), , , ( , , ). BTW, ( ) . #include -d .

, ++ (, <map> <vector>....) , ( Linux #include <vector> , )

, ++ - ( ). , ++ .

( , )

+4

preprocessor #include , , .

: , , a.h

// Our class
class A
{
    // Stuff for the class
};
// End of the class

a.cpp:

// Include header file
#include "a.h"
// Header file included

int main()
{
    // Code
}

,

// Include header file
// Our class
class A
{
    // Stuff for the class
};
// End of the class
// Header file included

int main()
{
    // Code
}

, , , .

, , , , .


, , , , .


, . ( ) , . ( ) , , .

, -, .

+4

All Articles