Header File

Header File 1
1
2
3
4
5
6
void Fn1(){}

void UseFn1_HF1()
{
  Fn1();
}


Header File 2
1
2
3
4
5
6
void Fn1(){}

void UseFn1_HF2()
{
  Fn1();
}


Source File
1
2
3
4
5
#include HeaderFile1
#include HeaderFile2
int main()
{
}


Obviously compilation of the project gives error due to Fn1 in both header files.

Question: Now is there any way I can make Fn1 local to both header files, without changing its name? (Hope you get the question!)
you can use namespaces

1
2
3
4
5
6
7
8
9
namespace a
{
inline void Fn1(){}

inline void UseFn1_HF1()
{
  Fn1();
}
}

1
2
3
4
5
6
7
8
9
namespace b
{
inline void Fn1(){}

inline void UseFn1_HF2()
{
  Fn1();
}
}

if you implement function in the header file they must be inline
Last edited on
You can also do this:
1
2
3
4
5
6
7
8
9
namespace n1
{
#include "header1"
}

namespace n2
{
#include "header2"
}
Any other ideas without using namespace?

And why Inline for the functions?
Last edited on
And why Inline for the functions?
because you have the implementation of the functions in them.
If you #include those headers more than once you should get multiple definition errors
Topic archived. No new replies allowed.