Aug 10, 2013 at 4:12am UTC
If I have 3 head files: A.h B.h C.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
//============================A.h=================================
#ifndef A_
#define A_
#include "B.h"
#endif
//============================B.h=================================
#ifndef _B
#define _B
#include "C.h"
#endif
//============================C.h=================================
#ifndef _C
#define _C
#include "new"
#include <iostream>
//Lack of memory
class NoMem
{
public :
NoMem(){}
};
//exception
void my_new_handler()
{
throw NoMem();
}
new_handler Old_Handler_ = std::set_new_handler(my_new_handler);
#endif
//============================Main.h=================================
#include "A.h"
int main()
{
NoMem example;
}
If run it, an error will be occurred :error C3861: 'NoMem': identifier not found
If I remove the #ifndef in file C, the program can run in the right way. But C.h is included twice if I do so. Is there any other method to solve this problem?
1 2 3 4
#ifndef _C
#define _C
#endif
Last edited on Aug 10, 2013 at 8:05am UTC
Aug 10, 2013 at 4:37am UTC
> If I have 3 head files: A.h B.h C.h
> #include "Hanoi.h"
???
Aug 10, 2013 at 9:51am UTC
Sorry, it should be #include "A.h"
Aug 10, 2013 at 10:12am UTC
I do not see where C.h can be included twice. Before posting a code it is a good idea to check your code snip yourself.