Question: I want to check a header in my source file and if its already defined, I want to undefine it.

Is it possible?

Answer: 
'including' something in c/c++ essentially means: make the [preprocessor](http://en.wikipedia.org/wiki/C_preprocessor) copy and paste the `#include <file>` directly into your source code (or better: the preprocessed version of your source code).

you can not make that copy and paste action undone. you can however '#undef' stuff introduced by that copy and paste action, but you have to do this for every atom you dislike, you just can't #undef the whole file.

to check, if a given header was already included, you have check if something from that header file is defined already. most headers contain so called 'guards' which look like 

```
 #ifndef FOO_H
 #define FOO_H
 /* lots of code */
 #endif

```

for a file called 'foo.h'. you could check for 'FOO\_H' like this:

```
 #ifdef FOO_H
 /* do your magic */
 #endif

```

example: 

```
 foo.h:
 #ifndef FOO_H
 #define FOO_H
 struct Foo { /* ... * };
 #endif

 bar.h:
 #include "foo.h"
 #ifdef FOO_H
 #undef Foo
 #endif

```

but that can lead to a lot of headaches if you are not aware of what exactly you are doing. IF your real problem is, that your compiler complaints about 'already declared stuff' then you are not guarding your header files against multiple inclusion...
You could stop the header being included - the simplest way would be to remove or comment out the `#include` directive.

You could also pre-define your guards so that the include is inneffective.

```
foo.h
#ifndef __FOO_H
#define __FOO_H

/* contents of foo.h */

#endif /* __FOO_H */

foo.cpp
#define __FOO_H
#include "foo.h"
/* contents of foo.cpp */

```

Using this strategy you could use the preprocessor to select whether to pre-define the guards, or even have inner guards within you header. 

If you really need only to have part of the file included, it would be better to split the file into two.