c++include-guards

Do include guards mean that only one .cpp file gets the header content?


When I include a header file, lets say,

//myheader.h
#ifndef MY_HEADER_H
#define MY_HEADER_H

//....

#endif

into,

//mycpp1.cpp
#include "myheader.h"

What I'm told is, when mycpp1.cpp includes myheader.h, MY_HEADER_H gets defined so any attempt to include it again will result false.

Now, if i want to include it in mycpp2.cpp.

//mpcpp2.cpp
#include "myheader.h"

Would it get included or does it use the same declarations when it was included the first time?


Solution

  • Preprocessor definitions are seperate for each file. So if you #include myheader.h into two seperate .cpp files, it will be included twice, not once. One per .cpp.