Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. error C2589: '(' : illegal token on right side of '::'
Qt 6.11 is out! See what's new in the release blog

error C2589: '(' : illegal token on right side of '::'

Scheduled Pinned Locked Moved Solved General and Desktop
26 Posts 6 Posters 10.3k Views 3 Watching
  • 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.
  • KroMignonK KroMignon

    @SPlatten said in error C2589: '(' : illegal token on right side of '::':

    , I've just kept it the same.

    No, you don't.
    You take the last element from the list with QList::takeLast(). So your list will be 1 item shorter as begin.

    SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #10

    @KroMignon , the original code, which would compile:

    groupList.back() = std::max(groupList.back(), sample);
    

    The replacement:

    double last = groupList.takeLast();
    
    if ( sample > last )
        last = sample;
    groupList.last() = last;
    

    How is the new code different from the original, except now it compiles?

    Kind Regards,
    Sy

    jsulmJ 1 Reply Last reply
    0
    • SPlattenS SPlatten

      @KroMignon , the original code, which would compile:

      groupList.back() = std::max(groupList.back(), sample);
      

      The replacement:

      double last = groupList.takeLast();
      
      if ( sample > last )
          last = sample;
      groupList.last() = last;
      

      How is the new code different from the original, except now it compiles?

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

      @SPlatten said in error C2589: '(' : illegal token on right side of '::':

      How is the new code different from the original, except now it compiles?

      You now overwrite the element before the last element: say you have 3 elements [A, B, C].
      After takeLast() you have [A, B].
      If you now execute groupList.last() = last; you will overwrite B.

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

      SPlattenS 1 Reply Last reply
      2
      • jsulmJ jsulm

        @SPlatten said in error C2589: '(' : illegal token on right side of '::':

        How is the new code different from the original, except now it compiles?

        You now overwrite the element before the last element: say you have 3 elements [A, B, C].
        After takeLast() you have [A, B].
        If you now execute groupList.last() = last; you will overwrite B.

        SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by SPlatten
        #12

        @jsulm , thank you, and the original just overrides the last item without removing it?

        So if I just change it to:

        double last = groupList.last();
        
        if ( sample > last )
            last = sample;
        groupList.last() = last;
        

        Kind Regards,
        Sy

        jsulmJ KroMignonK 2 Replies Last reply
        0
        • SPlattenS SPlatten

          @jsulm , thank you, and the original just overrides the last item without removing it?

          So if I just change it to:

          double last = groupList.last();
          
          if ( sample > last )
              last = sample;
          groupList.last() = last;
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #13

          @SPlatten said in error C2589: '(' : illegal token on right side of '::':

          and the original just overrides the last item without removing it?

          Yes.
          With your code you can use append() instead of groupList.last() = last; to get same behaviour.

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

          1 Reply Last reply
          1
          • SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by
            #14

            @jsulm , but I'm not sure thats what the original was trying to do either. I think the original code would just update the last item.

            Kind Regards,
            Sy

            jsulmJ 1 Reply Last reply
            0
            • SPlattenS SPlatten

              @jsulm , but I'm not sure thats what the original was trying to do either. I think the original code would just update the last item.

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

              @SPlatten said in error C2589: '(' : illegal token on right side of '::':

              I think the original code would just update the last item

              Yes, it updates the last element. Your code now removes the last element and updates the one before last (the new last element). So, to get same behaviour using takeLast() you have to append the element which takeLast REMOVES from the list:

              [A, B, C]
              after takeLast()
              [A, B]
              after append()
              [A, B, C*]
              C* is the updated C
              

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

              SPlattenS 1 Reply Last reply
              0
              • jsulmJ jsulm

                @SPlatten said in error C2589: '(' : illegal token on right side of '::':

                I think the original code would just update the last item

                Yes, it updates the last element. Your code now removes the last element and updates the one before last (the new last element). So, to get same behaviour using takeLast() you have to append the element which takeLast REMOVES from the list:

                [A, B, C]
                after takeLast()
                [A, B]
                after append()
                [A, B, C*]
                C* is the updated C
                
                SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on last edited by
                #16

                @jsulm , I think you missed one of my replies where I showed a replacement, changing the takeLast and replacing with just last.

                Kind Regards,
                Sy

                jsulmJ 1 Reply Last reply
                0
                • SPlattenS SPlatten

                  @jsulm , I think you missed one of my replies where I showed a replacement, changing the takeLast and replacing with just last.

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

                  @SPlatten The one using last() looks fine. Somehow overlooked it :-)

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

                  1 Reply Last reply
                  1
                  • SPlattenS SPlatten

                    @jsulm , thank you, and the original just overrides the last item without removing it?

                    So if I just change it to:

                    double last = groupList.last();
                    
                    if ( sample > last )
                        last = sample;
                    groupList.last() = last;
                    
                    KroMignonK Offline
                    KroMignonK Offline
                    KroMignon
                    wrote on last edited by KroMignon
                    #18

                    @SPlatten said in error C2589: '(' : illegal token on right side of '::':

                    thank you, and the original just overrides the last item without removing it?

                    Yes, that is the point:

                    • QList::takeLast() will return last element from QList and remove it from the list
                    • QList::last() will only return a reference to last element from QList and not change list size.

                    It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                    SPlattenS 1 Reply Last reply
                    0
                    • KroMignonK KroMignon

                      @SPlatten said in error C2589: '(' : illegal token on right side of '::':

                      thank you, and the original just overrides the last item without removing it?

                      Yes, that is the point:

                      • QList::takeLast() will return last element from QList and remove it from the list
                      • QList::last() will only return a reference to last element from QList and not change list size.
                      SPlattenS Offline
                      SPlattenS Offline
                      SPlatten
                      wrote on last edited by
                      #19

                      @KroMignon, still no idea why the compiler was complaining about the original?

                      groupList.back() = std::max(groupList.back(), sample);
                      

                      Kind Regards,
                      Sy

                      KroMignonK 1 Reply Last reply
                      0
                      • SPlattenS SPlatten

                        @KroMignon, still no idea why the compiler was complaining about the original?

                        groupList.back() = std::max(groupList.back(), sample);
                        
                        KroMignonK Offline
                        KroMignonK Offline
                        KroMignon
                        wrote on last edited by
                        #20

                        @SPlatten said in error C2589: '(' : illegal token on right side of '::':

                        still no idea why the compiler was complaining about the original?

                        I guess sampleand groupList.back() do not have same type and std::max() template will not be able to match them.
                        Perhaps using QList::constLast()?

                        // I prefere using Last() which is more clear as back()
                        groupList.last() = std::max(groupList.constLast(), sample);
                        

                        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                        SPlattenS 1 Reply Last reply
                        0
                        • KroMignonK KroMignon

                          @SPlatten said in error C2589: '(' : illegal token on right side of '::':

                          still no idea why the compiler was complaining about the original?

                          I guess sampleand groupList.back() do not have same type and std::max() template will not be able to match them.
                          Perhaps using QList::constLast()?

                          // I prefere using Last() which is more clear as back()
                          groupList.last() = std::max(groupList.constLast(), sample);
                          
                          SPlattenS Offline
                          SPlattenS Offline
                          SPlatten
                          wrote on last edited by
                          #21

                          @KroMignon , but they do, sample is passed in as "const double sample". It could be ambiguous as the back method has two implementations one returns "const double &" and the other returns "double&".

                          Kind Regards,
                          Sy

                          KroMignonK 1 Reply Last reply
                          0
                          • B Offline
                            B Offline
                            Bonnie
                            wrote on last edited by
                            #22

                            @SPlatten
                            How about replace std::max with qMax?

                            SPlattenS 1 Reply Last reply
                            0
                            • B Bonnie

                              @SPlatten
                              How about replace std::max with qMax?

                              SPlattenS Offline
                              SPlattenS Offline
                              SPlatten
                              wrote on last edited by
                              #23

                              @Bonnie Thanks, but I've moved on now, so much to do and so many errors and warnings to address.

                              Kind Regards,
                              Sy

                              1 Reply Last reply
                              0
                              • SPlattenS SPlatten

                                @KroMignon , but they do, sample is passed in as "const double sample". It could be ambiguous as the back method has two implementations one returns "const double &" and the other returns "double&".

                                KroMignonK Offline
                                KroMignonK Offline
                                KroMignon
                                wrote on last edited by
                                #24

                                @SPlatten said in error C2589: '(' : illegal token on right side of '::':

                                It could be ambiguous as the back method has two implementations one returns "const double &" and the other returns "double&".

                                Yes, depending on compiler this can be a problem. Again this is why I suggest you to change by using QList::last() and QList::constLast() to avoid ambiguity:

                                groupList.last() = std::max(groupList.constLast(), sample);
                                

                                It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                                1 Reply Last reply
                                1
                                • S Offline
                                  S Offline
                                  SimonSchroeder
                                  wrote on last edited by
                                  #25

                                  Your own win.h header suggests that you are compiling for Windows. There is a really old problem with including Windows.h as it defines a macro max. Most likely this is your problem. Even in std::max(...) max will be expanded which would explain your errors.

                                  The solution to this is that you define NOMINMAX either globally or before you include Windows.h (since it seems that you always include Windows.h through your own header win.h).

                                  KroMignonK 1 Reply Last reply
                                  2
                                  • S SimonSchroeder

                                    Your own win.h header suggests that you are compiling for Windows. There is a really old problem with including Windows.h as it defines a macro max. Most likely this is your problem. Even in std::max(...) max will be expanded which would explain your errors.

                                    The solution to this is that you define NOMINMAX either globally or before you include Windows.h (since it seems that you always include Windows.h through your own header win.h).

                                    KroMignonK Offline
                                    KroMignonK Offline
                                    KroMignon
                                    wrote on last edited by
                                    #26

                                    @SimonSchroeder said in error C2589: '(' : illegal token on right side of '::':

                                    here is a really old problem with including Windows.h as it defines a macro max

                                    I didn't know this, thanks for this!
                                    After a quit google search a found an interesting post on stackoverflow ==> https://stackoverflow.com/questions/13416418/define-nominmax-using-stdmin-max

                                    I new thing a learned today :D

                                    It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                                    1 Reply Last reply
                                    0

                                    • Login

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