Multiple Compiles of Header Files ◆Header files Typically included multiple times e.g.,class interface included by class implementation and program file Must only be compiled once! No guarantee "which #include"in which file, compiler might see first ◆Use preprocessor Tell compiler to include header only once Copyright 2006 Pearson Addison-Wesley.All rights reserved. 11-11
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 11-11 Multiple Compiles of Header Files ¨ Header files ¨ Typically included multiple times ¨ e.g., class interface included by class implementation and program file ¨ Must only be compiled once! ¨ No guarantee "which #include" in which file, compiler might see first ¨ Use preprocessor ¨ Tell compiler to include header only once
Using #ifndef Header file structure: ◆#ifndef FNAME H #define FNAME H .//Contents of header file #endif FNAME typically name of file for consistency,readability This syntax avoids multiple definitions of header file Copyright006 Pearson Addison-Wesley.All rights reserved. 11-12
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 11-12 Using #ifndef ¨ Header file structure: ¨ #ifndef FNAME_H #define FNAME_H . //Contents of header file . #endif ¨ FNAME typically name of file for consistency, readability ¨ This syntax avoids multiple definitions of header file