Hello everyone iam just looking through the header guards application in c++,I know that header guards are used to include content of any file at once,i have the following scenario as,
a.h
#include<string>
#include "b.h"
std::string getA()
{
return "A";
}
b.h
#include<string>
#include "a.h"
#ifndef B_H
#define B_H
std::string getB()
{
return "B";
}
#endif
and both.cpp
#include<iostream>
#include"b.h"
#include"a.h"
using namespace std;
int main()
{
cout<<getA();
cout<<getB();
return 0;
}
please explain me how does the final both.cpp contains as we have two times called "#include "b.h" ".I think iam making sense here.Thanks in advance.Please help needed guys. Since a.h has no header guard and the function defination of getA should be included 2 times in both.cpp, but the program ran successfully.Please help me in figuring out final both.cpp code.