When you use the VC menu to add a class, you will find that the automatically generated code is always like the following:
# If! Defined (afx_xxxx1_included _)
# Define afx_xxxx1_encoded _
Code
# Endif
This is to prevent the header file from being repeatedly contained. Repeated inclusion can be illustrated in the following example: for example, there is a header file. h, which contains a function FA and another header file B. h. The function FB is provided. If fa is required for FB implementation, B. h must contain. h; if a function in the CPP file needs to use FA and Fb, it must contain. H and B. h,. h. Compile the program with the following error:
Error c2084: function 'bool _ cdecl FA () 'already has a body
The solution is to add the following in a. h:
# Ifndef
# Define
Original code
# Endif
The sample source code is as follows:
// A. h
# Ifndef
# Define
Bool aorb (bool)
{
Return;
}
# Endif
// B. H
# Include "A. H"
Bool cord (bool)
{
Return aorb ();
}
// A. cpp
# Include "A. H"
# Include "B. H"
Int main ()
{
Bool a = 0;
Bool B = aorb ();
Bool c = cord (B );
Getchar ();
Return 0;
}