Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. "unterminated conditional directive" Issue for #ifndef directive
QtWS25 Last Chance

"unterminated conditional directive" Issue for #ifndef directive

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 4 Posters 13.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    skymouse
    wrote on last edited by
    #1

    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
    
    aha_1980A jsulmJ 2 Replies Last reply
    0
    • S skymouse

      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
      
      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @skymouse

      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

      Qt has to stay free or it will die.

      1 Reply Last reply
      2
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        Its a clang thing.
        https://bugreports.qt.io/browse/QTCREATORBUG-20883

        1 Reply Last reply
        2
        • S skymouse

          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
          
          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved