Use of #ifndef | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Use of #ifndef

2nd Sep 2019, 3:35 PM
Abhinav Pathak
Abhinav Pathak - avatar
5 Answers
+ 1
Please clarify your question. Share code if it concerns a code, and mention language in Relevant Tags to narrow down scoping. `#ifndef`is preprocessor directive, it is more about deciding which portion of the source code to be processed rather than OOP related (classes - mentioned in Tags). http://www.cplusplus.com/doc/tutorial/preprocessor/
2nd Sep 2019, 4:34 PM
Ipang
+ 1
Use of #ifndef here is to prevent MYCLASS_H from being defined more than once. #ifndef MYCLASS_H // if MYCLASS_H is not defined #define MYCLASS_H // now define it // Class definition codes ... #endif // for #ifndef MYCLASS_H The lines between #ifndef and #endif is only compiled when MYCLASS_H is not defined yet, once it is defined the #ifndef will give false, thus the lines between will not be processed again. Hth, cmiiw
2nd Sep 2019, 7:09 PM
Ipang
0
#ifndef MYCLASS_H #define MYCLASS_H class MyClass { public: MyClass(); protected: private: }; #endif // MYCLASS_H
2nd Sep 2019, 5:26 PM
Abhinav Pathak
Abhinav Pathak - avatar
0
Okay, but I still don't get what the question is. And you haven't revised your original question to add clarity.
2nd Sep 2019, 5:37 PM
Ipang
0
Is using #ifndef important can't using just #define enough
2nd Sep 2019, 5:40 PM
Abhinav Pathak
Abhinav Pathak - avatar