c++ header file

"Theexamplealsodemonstratesanimportant C++softwareengineering concept—usinga “preprocessor wrapper” in headerstoprevent the code in theheaderfrom being included intothe same source code file more than
once.Sincea classcan be definedonlyonce, using such preprocessordirectives prevents
multiple definition errors."



please understand any one in simple way . i can not understand above paragraph. specially “preprocessor wrapper”???



thanks in advance
I think you're talking about Include Guards.
They prevent the declaring classes, functions, or variables twice.

for a "my_header.h" file:
1
2
3
4
#ifndef HEADER_H
#define HEADER_H
/** relevant stuff goes here, like a class definition **/
#endif 


If you didn't have those guards, but had two other files try to both #include "header.h" , you'd get error messages.

(Had other stuff written but accidentally pressed backspace...)
Last edited on
Topic archived. No new replies allowed.