Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. C++ % " ?
Forum Updated to NodeBB v4.3 + New Features

C++ % " ?

Scheduled Pinned Locked Moved Solved C++ Gurus
26 Posts 9 Posters 6.9k Views 6 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.
  • JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #4

    Oh dear, oh dear. Thanks.

    1 Reply Last reply
    3
    • K Offline
      K Offline
      Konstantin Tokarev
      wrote on last edited by
      #5

      They didn't overload operator , so everything is under control :)

      JonBJ 1 Reply Last reply
      4
      • K Konstantin Tokarev

        They didn't overload operator , so everything is under control :)

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #6

        @Konstantin-Tokarev
        LOL! Wait!! You can overload the C comma operator? OMG!

        kshegunovK J.HilkJ 2 Replies Last reply
        0
        • JonBJ JonB

          @Konstantin-Tokarev
          LOL! Wait!! You can overload the C comma operator? OMG!

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #7

          @JonB said in C++ % " ?:

          You can overload the C comma operator?

          Of course you can. There are only a handful of operators that can't be overloaded; the scope resolution ::, the member access . the pointer to member access .* and the short if ?:

          Read and abide by the Qt Code of Conduct

          JonBJ 1 Reply Last reply
          3
          • kshegunovK kshegunov

            @JonB said in C++ % " ?:

            You can overload the C comma operator?

            Of course you can. There are only a handful of operators that can't be overloaded; the scope resolution ::, the member access . the pointer to member access .* and the short if ?:

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #8

            @kshegunov
            Haven't seen you in a while!

            I was thinking earlier: why couldn't/didn't C++ allow defining your own operators then? I have used languages where you can. By the time Qt is having QString override an operator to add some convenient behaviour, it's plain confusing that it picks an existing "modulus" symbol to do it :( If you're going to change the meaning so much, you only really need to be able to specify the precedence and you might as well be free to pick your own operator characters.

            Going back to the , operator. I didn't realise it was a true operator, that means you have to be consistent about the types on each side, I didn't think the left-hand side mattered, I thought it just returned the right-hand side.

            kshegunovK 1 Reply Last reply
            0
            • JonBJ JonB

              @kshegunov
              Haven't seen you in a while!

              I was thinking earlier: why couldn't/didn't C++ allow defining your own operators then? I have used languages where you can. By the time Qt is having QString override an operator to add some convenient behaviour, it's plain confusing that it picks an existing "modulus" symbol to do it :( If you're going to change the meaning so much, you only really need to be able to specify the precedence and you might as well be free to pick your own operator characters.

              Going back to the , operator. I didn't realise it was a true operator, that means you have to be consistent about the types on each side, I didn't think the left-hand side mattered, I thought it just returned the right-hand side.

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by kshegunov
              #9

              @JonB said in C++ % " ?:

              @kshegunov
              Haven't seen you in a while!

              many-a-work.

              I was thinking earlier: why couldn't/didn't C++ allow defining your own operators then?

              It could've, I imagine it's a conscious choice not to make it even more confusing.

              Going back to the , operator. I didn't realise it was a true operator

              Yes, albeit a low-priority one.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              0
              • JonBJ JonB

                @Konstantin-Tokarev
                LOL! Wait!! You can overload the C comma operator? OMG!

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #10

                @JonB said in C++ % " ?:

                @Konstantin-Tokarev
                LOL! Wait!! You can overload the C comma operator? OMG!

                There is hardly a thing one can't change/overload in c++.
                But you do, the operation should be somewhat related to the original. Otherwise you'll end up with confusion and lost development time.

                I'm looking at you boost 0_1537780536073_34207ed0-bfd8-4865-9798-02d5853acddc-image.png


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                JonBJ 1 Reply Last reply
                1
                • J.HilkJ J.Hilk

                  @JonB said in C++ % " ?:

                  @Konstantin-Tokarev
                  LOL! Wait!! You can overload the C comma operator? OMG!

                  There is hardly a thing one can't change/overload in c++.
                  But you do, the operation should be somewhat related to the original. Otherwise you'll end up with confusion and lost development time.

                  I'm looking at you boost 0_1537780536073_34207ed0-bfd8-4865-9798-02d5853acddc-image.png

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #11

                  @J.Hilk
                  LOL, I don't know about Boost. But how's about the subject of this post: how is this QString % operator related to original modulus?

                  K J.HilkJ 2 Replies Last reply
                  0
                  • K Offline
                    K Offline
                    koahnig
                    wrote on last edited by
                    #12

                    Hope you cannot overload ';' That would probably cause the ultimate confusion.

                    Vote the answer(s) that helped you to solve your issue(s)

                    JonBJ 1 Reply Last reply
                    2
                    • K koahnig

                      Hope you cannot overload ';' That would probably cause the ultimate confusion.

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #13

                      @koahnig ; is not an operator. I believe it is a "statement separator" (whereas Pascal had it as a "statement terminator"... or is it the other way round?).

                      K 1 Reply Last reply
                      3
                      • JonBJ JonB

                        @koahnig ; is not an operator. I believe it is a "statement separator" (whereas Pascal had it as a "statement terminator"... or is it the other way round?).

                        K Offline
                        K Offline
                        koahnig
                        wrote on last edited by
                        #14

                        @JonB

                        Thanks for clarification, I am so happy about that ;)

                        However, with the ancient FORTRAN they discussed a COME FROM statement
                        Therefore, you never know what somebody will come up with. At least FORTRAN did not require a "statement separator" nor a "statement terminator". The logical end of aline was the end of the punching card after 80 chars respectively you had to subtract 8 digits for the line number.

                        Vote the answer(s) that helped you to solve your issue(s)

                        1 Reply Last reply
                        1
                        • JonBJ JonB

                          @J.Hilk
                          LOL, I don't know about Boost. But how's about the subject of this post: how is this QString % operator related to original modulus?

                          K Offline
                          K Offline
                          Konstantin Tokarev
                          wrote on last edited by
                          #15

                          @JonB said in C++ % " ?:

                          @J.Hilk
                          LOL, I don't know about Boost. But how's about the subject of this post: how is this QString % operator related to original modulus?

                          modulus has no established meaning for strings, and % looks somewhat similar to + :)

                          1 Reply Last reply
                          3
                          • K Offline
                            K Offline
                            Konstantin Tokarev
                            wrote on last edited by
                            #16

                            Though you should better define QT_USE_QSTRINGBUILDER and simply use + everywhere instead of %

                            JonBJ 1 Reply Last reply
                            4
                            • K Konstantin Tokarev

                              Though you should better define QT_USE_QSTRINGBUILDER and simply use + everywhere instead of %

                              JonBJ Offline
                              JonBJ Offline
                              JonB
                              wrote on last edited by
                              #17

                              @Konstantin-Tokarev said in C++ % " ?:

                              Though you should better define QT_USE_QSTRINGBUILDER and simply use + everywhere instead of %

                              Ooohhh, the plot thickens...!

                              1 Reply Last reply
                              0
                              • JonBJ JonB

                                @J.Hilk
                                LOL, I don't know about Boost. But how's about the subject of this post: how is this QString % operator related to original modulus?

                                J.HilkJ Offline
                                J.HilkJ Offline
                                J.Hilk
                                Moderators
                                wrote on last edited by
                                #18

                                @JonB Qt has ome confusing operaters as well.

                                for example take QVectors +=

                                QVector<T> QVector::operator+(const QVector<T> &other) const
                                

                                I would asume this to be Vector addtion

                                QVector v1{a,b,c};
                                QVector v2{d,e,f};
                                
                                //What one would expect
                                v1 += v2; -> {a+d, b+e, c+f}
                                
                                //what one gets
                                v1 +=v2; _> {a,b,c,d,e,f}
                                

                                I mean, this technically makes sense. QVector is to generic to have this operation, thats why there is QVector2D, 3D, 4D etc

                                It still confused me the first time I used it. I did not expect += to be equal to .append() or <<;

                                In this paticular example I have would prefere a missing += operator :-).


                                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                Q: What's that?
                                A: It's blue light.
                                Q: What does it do?
                                A: It turns blue.

                                jsulmJ JKSHJ 2 Replies Last reply
                                0
                                • J.HilkJ J.Hilk

                                  @JonB Qt has ome confusing operaters as well.

                                  for example take QVectors +=

                                  QVector<T> QVector::operator+(const QVector<T> &other) const
                                  

                                  I would asume this to be Vector addtion

                                  QVector v1{a,b,c};
                                  QVector v2{d,e,f};
                                  
                                  //What one would expect
                                  v1 += v2; -> {a+d, b+e, c+f}
                                  
                                  //what one gets
                                  v1 +=v2; _> {a,b,c,d,e,f}
                                  

                                  I mean, this technically makes sense. QVector is to generic to have this operation, thats why there is QVector2D, 3D, 4D etc

                                  It still confused me the first time I used it. I did not expect += to be equal to .append() or <<;

                                  In this paticular example I have would prefere a missing += operator :-).

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

                                  @J.Hilk To be honest I would be rather confused if it would do

                                  v1 += v2; -> {a+d, b+e, c+f}
                                  

                                  A vector is not a number or something, it is a container. Or is it because it is called "vector" and you expect it to behave like a vector in math? :-)

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

                                  K J.HilkJ 2 Replies Last reply
                                  0
                                  • jsulmJ jsulm

                                    @J.Hilk To be honest I would be rather confused if it would do

                                    v1 += v2; -> {a+d, b+e, c+f}
                                    

                                    A vector is not a number or something, it is a container. Or is it because it is called "vector" and you expect it to behave like a vector in math? :-)

                                    K Offline
                                    K Offline
                                    koahnig
                                    wrote on last edited by
                                    #20

                                    @jsulm said in C++ % " ?:

                                    @J.Hilk To be honest I would be rather confused if it would do

                                    v1 += v2; -> {a+d, b+e, c+f}
                                    

                                    A vector is not a number or something, it is a container. Or is it because it is called "vector" and you expect it to behave like a vector in math? :-)

                                    That is debatable and apparently dependent on your background. The foprm you find confusing would be the most logical version for me.

                                    Vote the answer(s) that helped you to solve your issue(s)

                                    jsulmJ 1 Reply Last reply
                                    0
                                    • jsulmJ jsulm

                                      @J.Hilk To be honest I would be rather confused if it would do

                                      v1 += v2; -> {a+d, b+e, c+f}
                                      

                                      A vector is not a number or something, it is a container. Or is it because it is called "vector" and you expect it to behave like a vector in math? :-)

                                      J.HilkJ Offline
                                      J.HilkJ Offline
                                      J.Hilk
                                      Moderators
                                      wrote on last edited by
                                      #21

                                      @jsulm I used to use only QList as a container, and one day I needed to do Vector operations. In my youthfull naiveté I assumed QVector = linear algebra vector.
                                      I learned quickly thats not the case 🤷

                                      Ever since, I prefere using QVector over QList.😉


                                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                      Q: What's that?
                                      A: It's blue light.
                                      Q: What does it do?
                                      A: It turns blue.

                                      1 Reply Last reply
                                      0
                                      • K koahnig

                                        @jsulm said in C++ % " ?:

                                        @J.Hilk To be honest I would be rather confused if it would do

                                        v1 += v2; -> {a+d, b+e, c+f}
                                        

                                        A vector is not a number or something, it is a container. Or is it because it is called "vector" and you expect it to behave like a vector in math? :-)

                                        That is debatable and apparently dependent on your background. The foprm you find confusing would be the most logical version for me.

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

                                        @koahnig Yes, that's true.
                                        @J-Hilk I'm actually wondering why it is called vector? Something like "QDynamicArray" would be less confusing.

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

                                        K kshegunovK 2 Replies Last reply
                                        0
                                        • jsulmJ jsulm

                                          @koahnig Yes, that's true.
                                          @J-Hilk I'm actually wondering why it is called vector? Something like "QDynamicArray" would be less confusing.

                                          K Offline
                                          K Offline
                                          koahnig
                                          wrote on last edited by
                                          #23

                                          @jsulm

                                          In the mathematical sense it is alwways a vector, but in spaces with different dimensions. All operators are bascially identical, therefore "real" engineers can accept this. Personally I doubt that the definition of basically changing the space dimension during an addition is conform with pure mathematics. On the other hand you never know what they think/thoght in those areas ;)

                                          Vote the answer(s) that helped you to solve your issue(s)

                                          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