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. 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 6.8k 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    I'm working on porting an existing project which was originally developed for Qt 4.8. I have porting this to Qt 5.8 and updating various other libraries to later revisions.

    I'm getting the error C2589 during compile on:

    QList<double>& groupList = m_sampleHistory[group];
    if(groupList.size() == 0) {
        groupList.push_back(0.0);
    }
    groupList.back() = std::max(groupList.back(), sample);
    

    The error is shown on the last line above. I didn't write this code and it doesn't look correct as back() returns a 'const double&'. The headers that are include are:

    #include "win.h"
    #include <algorithm>
    #include <iostream>
    #include <string>
    
    #include "QVariant"
    #include "QMap"
    #include "QList"
    #include "QString"
    #include "boost/array.hpp"
    

    win.h is a header I created which contains:

    #ifndef WIN_H
        #define WIN_H
    
        #ifndef AF_IPX
            #ifndef WIN32_LEAN_AND_MEAN
               #define WIN32_LEAN_AND_MEAN 1
            #endif
            #ifndef WIN32
                #define WIN32
            #endif
            #include <stdio.h>
            #include <stdlib.h>
            #include <WinSock2.h>
            #include <Windows.h>
        #endif
    #endif
    

    Kind Regards,
    Sy

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

      @sierdzio , also just tried your example and it won't allow it:

      const double existing = groupList.takeLast();
      groupList.append(std::max(existing, sample));
      

      The last line has exclamantion mark on it , the errors are:

      error: C2589: '(' : illegal token on right side of '::'    
      error: C2143: syntax error : missing ')' before '::'
      error: C2661: 'QList<double>::append' : no overloaded function takes 0 arguments
      error: C2059: syntax error : ')'
      

      All of those on that line. Having just looked at the details on QList, I can see that the const version of back is an overloaded version, there is also an identical version without const.
      In the end, this works:

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

      Kind Regards,
      Sy

      KroMignonK 1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by sierdzio
        #2

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

        groupList.back()

        Try this:

        const double existing = groupList.takeLast();
        groupList.append(std::max(existing, sample));
        

        although it returns the same value.

        It's not as efficient, perhaps, but more readable. And should compile ;-)

        (Z(:^

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

          @sierdzio , thanks , to me the logic just doesn't look right I have it compiling now, somehow its assigning a value to a const double reference.

          The error has now changed, now I'm getting:

          ocidl.h(45) : error C2146: syntax error : missing ';' before identifier
          

          Kind Regards,
          Sy

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #4

            Is sample also a double? Perhaps std::max gets confused.

            (Z(:^

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

              @sierdzio , yes, passed in as const double.

              Kind Regards,
              Sy

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

                @sierdzio , also just tried your example and it won't allow it:

                const double existing = groupList.takeLast();
                groupList.append(std::max(existing, sample));
                

                The last line has exclamantion mark on it , the errors are:

                error: C2589: '(' : illegal token on right side of '::'    
                error: C2143: syntax error : missing ')' before '::'
                error: C2661: 'QList<double>::append' : no overloaded function takes 0 arguments
                error: C2059: syntax error : ')'
                

                All of those on that line. Having just looked at the details on QList, I can see that the const version of back is an overloaded version, there is also an identical version without const.
                In the end, this works:

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

                Kind Regards,
                Sy

                KroMignonK 1 Reply Last reply
                0
                • SPlattenS SPlatten

                  @sierdzio , also just tried your example and it won't allow it:

                  const double existing = groupList.takeLast();
                  groupList.append(std::max(existing, sample));
                  

                  The last line has exclamantion mark on it , the errors are:

                  error: C2589: '(' : illegal token on right side of '::'    
                  error: C2143: syntax error : missing ')' before '::'
                  error: C2661: 'QList<double>::append' : no overloaded function takes 0 arguments
                  error: C2059: syntax error : ')'
                  

                  All of those on that line. Having just looked at the details on QList, I can see that the const version of back is an overloaded version, there is also an identical version without const.
                  In the end, this works:

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

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

                  double last = groupList.takeLast();

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

                  I am not sure this is the same as groupList.back() = std::max(groupList.back(), sample);

                  I think your should change to

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

                  or

                  groupList.insert(std::max(groupList.takeLast(), double(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
                  1
                  • KroMignonK KroMignon

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

                    double last = groupList.takeLast();

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

                    I am not sure this is the same as groupList.back() = std::max(groupList.back(), sample);

                    I think your should change to

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

                    or

                    groupList.insert(std::max(groupList.takeLast(), double(sample)));
                    
                    SPlattenS Offline
                    SPlattenS Offline
                    SPlatten
                    wrote on last edited by
                    #8

                    @KroMignon , the original code was setting last in the same way, I've just kept it the same.

                    Kind Regards,
                    Sy

                    KroMignonK 1 Reply Last reply
                    0
                    • SPlattenS SPlatten

                      @KroMignon , the original code was setting last in the same way, I've just kept it the same.

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

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

                      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
                      1
                      • 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

                                            • Login

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