How #ifndef works in different files

484 views Asked by At

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?

1

There are 1 answers

0
daniel gratzer On BEST ANSWER

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