Avoid including a library twice

Hi all,
My problem is that I have a main file which includes "file1.h" and "file2.h" and both of them include another "file3.h". That causes a problem of redefinition.

Searching in internet I found a solution that would be including "file3.h" in the other files like that:

1
2
3
#ifndef FILE3_H
#define FILE3_H
#endif 


But my problem is that I use a full path to include "file3.h", something like:

"C:\Documents and Settings\...\file3.h"

And I think the above solution won't work. Anyone could help me to solve this problem?

Thanks,
That solution works like this:
1
2
3
4
#ifndef FILE3_H
#define FILE3_H
//Code
#endif 
If the macro 'FILE3_H' wasn't defined, define FILE3_H and do the code.
If that macro was already defined, skip everything and do nothing.

That's the standard way to avoid multiple inclusion of the same file.
If you are using VC++ there also is the #pragma once directive which will have the same result but it isn't standard

Last edited on
Oh, I understood! Now it seems obvious! I though that by some convention FILE3_H would represent file3.h

Thank you for the clarification :)
Topic archived. No new replies allowed.