#ifndef TREE_NODE
#include "TreeNode.h"
#endif
#ifndef SEARCH_TREE
#include "SearchTree.h"
#endif
what does this code mean?
Printable View
#ifndef TREE_NODE
#include "TreeNode.h"
#endif
#ifndef SEARCH_TREE
#include "SearchTree.h"
#endif
what does this code mean?
This means that if TREE_NODE is not defined already, then include TreeNode.h, which will most likely #define TREE_NODE. It's to prevent including a file twice.
#ifndef stands for "If Not Defined"
C / C++ supports multiple declaration but single definition.
Hence if you have a class definition or something like that in a headerfile, if you include it more than once directly or indirectly, the compiler would generate an error.
#ifndef XYZ
#define XYZ
// your class definitions etc comes here
#endif
When the compiler reads it for the first time, XYZ is not defined, hence it would enter the conditional-preprocessor directive and within that we are defining XYZ. If it revisits this, any other time, XYZ is defined and hence would not enter the coditional-preprocessor directive, thus preventing multiple definition.
To make your code more modular. Say you have two or more files (modules) that need to include iostream.h. Each file can say "If iostream has not been included yet, then include it now."