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. New Errors when moving C++ code to QT Creator

New Errors when moving C++ code to QT Creator

Scheduled Pinned Locked Moved Solved General and Desktop
qtcreatorc++clanggcc
6 Posts 4 Posters 2.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.
  • A Offline
    A Offline
    A123
    wrote on last edited by A123
    #1

    I'm getting new errors when migrating from using makefiles and clang 4.0.1 on linux mint to using QTcreator as an IDE for convenience. Specifically its complaining that private members are being accessed.... 'is private within this context.' type error

    ie this line gives me an error

     assert( variableIndex(0,i)<organism_->numParameter());
    

    because

    private:
     
     // A pointer to the organism class to be able to get all possible data fields 
     Organism *organism_;
    

    I sorta understand the error but this is the way the code was when I received it, its been used by others for years and it worked perfectly AFAIK with gcc and clang before I started using qtcreator which complained. So I don't want to change it unless I'm sure the code is the problem. So what is wrong? Is it the code or one of the compilers? If you want to see additional code for context I can provide it. The old makefiles appear to include the problematic files so it doesn't look like just a matter of the errors only appearing when a previously unused file was included.

    jsulmJ JKSHJ 2 Replies Last reply
    0
    • A A123

      I'm getting new errors when migrating from using makefiles and clang 4.0.1 on linux mint to using QTcreator as an IDE for convenience. Specifically its complaining that private members are being accessed.... 'is private within this context.' type error

      ie this line gives me an error

       assert( variableIndex(0,i)<organism_->numParameter());
      

      because

      private:
       
       // A pointer to the organism class to be able to get all possible data fields 
       Organism *organism_;
      

      I sorta understand the error but this is the way the code was when I received it, its been used by others for years and it worked perfectly AFAIK with gcc and clang before I started using qtcreator which complained. So I don't want to change it unless I'm sure the code is the problem. So what is wrong? Is it the code or one of the compilers? If you want to see additional code for context I can provide it. The old makefiles appear to include the problematic files so it doesn't look like just a matter of the errors only appearing when a previously unused file was included.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @A123 said in New Errors when moving C++ code to QT Creator:

      So what is wrong?

      Accessing private members is wrong. There is a reason why they are private. You should fix the code.
      Also, where exactly is this code called

      assert( variableIndex(0,i)<organism_->numParameter());
      

      ?
      Is it called in the same class where organism_ is declared?

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

      A 1 Reply Last reply
      2
      • jsulmJ jsulm

        @A123 said in New Errors when moving C++ code to QT Creator:

        So what is wrong?

        Accessing private members is wrong. There is a reason why they are private. You should fix the code.
        Also, where exactly is this code called

        assert( variableIndex(0,i)<organism_->numParameter());
        

        ?
        Is it called in the same class where organism_ is declared?

        A Offline
        A Offline
        A123
        wrote on last edited by
        #3

        @jsulm its called within a function of Class ParamCopy. ParamCopy is derived from BaseReact which is where

        private:
        
         Organism *organism_;
        

        is

        jsulmJ 1 Reply Last reply
        0
        • A A123

          @jsulm its called within a function of Class ParamCopy. ParamCopy is derived from BaseReact which is where

          private:
          
           Organism *organism_;
          

          is

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @A123 Well, then this code is broken and I'm wondering how it was compiling before. Private elements of a base class can't be accessed from derived classes in C++. This is the case since the beginning of C++. You need to fix the code.

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

          1 Reply Last reply
          2
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            To make it more clear, protected: would work, private: can't work

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            3
            • A A123

              I'm getting new errors when migrating from using makefiles and clang 4.0.1 on linux mint to using QTcreator as an IDE for convenience. Specifically its complaining that private members are being accessed.... 'is private within this context.' type error

              ie this line gives me an error

               assert( variableIndex(0,i)<organism_->numParameter());
              

              because

              private:
               
               // A pointer to the organism class to be able to get all possible data fields 
               Organism *organism_;
              

              I sorta understand the error but this is the way the code was when I received it, its been used by others for years and it worked perfectly AFAIK with gcc and clang before I started using qtcreator which complained. So I don't want to change it unless I'm sure the code is the problem. So what is wrong? Is it the code or one of the compilers? If you want to see additional code for context I can provide it. The old makefiles appear to include the problematic files so it doesn't look like just a matter of the errors only appearing when a previously unused file was included.

              JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by JKSH
              #6

              @A123 said in New Errors when moving C++ code to QT Creator:

              its been used by others for years and it worked perfectly AFAIK with gcc and clang before I started using qtcreator which complained.

              Here's my guess: Previously, the assert() macro was disabled. This caused the illegal code to be effectively "commented out", so the compiler didn't detect it. After the migration, the assert() macro was no longer disabled, so the compiler now sees the bad code and (correctly) complains.

              See http://www.cplusplus.com/reference/cassert/assert/. You could make your code work again by defining the NDEBUG macro, but be careful: This will disable all assert()s which might cause other errors to go undetected.

              P.S. The compiler is the one that complained, not Qt Creator.

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              5

              • Login

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