c++ - Quick question regarding Conditional Compilation (ifndef) -


This is probably a pretty silly question, but I need to make sure. I have given a class declaration in the header file eg.

  #ifndef file_H #define file_H before class {private: public:}; #endif  

And I must write the definition of method in the same file, which I have done, my question is to be "#endif" where it is just after class classification or what is this class The method goes to the end of my file after defragment ?.

file end

this #ifndef pattern The goal of this form is to prevent a situation where the same declaration or definition is seen twice in the compiling unit.

This is done because the C file can contain several H files, which may include the same file anywhere on the chain if you run without a preprocessor, you have the H file There were several copies of that. In this way, you have many copies, but after the first encounter, the preprocessor ignores everything.

Since you are going to be defining more than one, if you have to add method definitions in the header file, Then place them within #endif


Comments