Solved "unterminated conditional directive" Issue for #ifndef directive
-
I create two classes and they include each other. I got an issue notification about "unterminated conditional directive". But I can compile and run the whole application successfully. How can I remove this issue warning? Or what is the standard way of cross reference of two classes?
Qt version is Qt 5.12. Qt Creator version is 4.8.2. I use GCC 8.21 to compile source code. Analyzer use default configuration - "Clang-Tidy and Clazy preselected checks [built-in]".//CFemale.h #ifndef CFEMALE_H //"unterminated conditional directive" issue notification #define CFEMALE_H #include "CMale.h" class CMale; class CFemale { public: CFemale(); CMale * temp; }; #endif // CFEMALE_H
//CMale.h #ifndef CMALE_H //"unterminated conditional directive" issue notification #define CMALE_H #include "CFemale.h" class CFemale; class CMale { public: CMale(); CFemale * temp; }; #endif // CMALE_H
-
Beside the error message, which I won't comment on, you almost doing it right by forward-declaring the classes with
class Male
. That avoids the circular references.So how about this:
//CFemale.h #ifndef CFEMALE_H //"unterminated conditional directive" issue notification #define CFEMALE_H class CMale; class CFemale { public: CFemale(); CMale * temp; }; #endif // CFEMALE_H //CMale.h #ifndef CMALE_H //"unterminated conditional directive" issue notification #define CMALE_H class CFemale; class CMale { public: CMale(); CFemale * temp; }; #endif // CMALE_H
With modern compilers, it's also possible to convert the include guards to
#pragma once
.Regards
-
Hi
Its a clang thing.
https://bugreports.qt.io/browse/QTCREATORBUG-20883 -
@skymouse If you use forward declaration why do you include the header files then? You have circular dependencies between both header files. Just remove the includes and put them in the cpp files.