Search code examples
c++c-preprocessorconditional-compilationifndef

How #ifndef works in different files


So I was trying to include the libraries I have declared in my main.cpp to my header.h

//In my main.cpp
#include <cmath>
#include <deque>
#include <vector>

using namespace std;


//In my header.h
#ifndef HANOI_H
#define HANOI_H

#include <cmath>
#include <deque>

using namespace std;



#endif

Would this check my main.cpp to see wether the 3 libraries and namespace exist with the corresponding variable HANOI_H?


Solution

  • Yes because the #includes are performed which actually substitutes everything into 1 file. Therefore #ifndef never cares about multiple files or knows about them.