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. Strong typing problem

Strong typing problem

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

    @J-Hilk , @JKSH
    Actually, I wasn't!

    Bearing in mind that I'm Python not C++ so I don't see the sources, all I get to see for Qt is the documentation, where the declarations of each class show what it's derived from. Now, apart from base classes like QWidget or QObject, which may or may not be polymorphic I can't tell, I haven't seen a single class which lists anything other than one class from which it is derived?

    VRoninV 1 Reply Last reply
    0
    • JonBJ JonB

      @J-Hilk , @JKSH
      Actually, I wasn't!

      Bearing in mind that I'm Python not C++ so I don't see the sources, all I get to see for Qt is the documentation, where the declarations of each class show what it's derived from. Now, apart from base classes like QWidget or QObject, which may or may not be polymorphic I can't tell, I haven't seen a single class which lists anything other than one class from which it is derived?

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #9

      @JonB The methods tagged with virtual are polymorphic. for example: QAbstractItemModel::data and QWidget::event

      "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

      JonBJ 1 Reply Last reply
      4
      • VRoninV VRonin

        @JonB The methods tagged with virtual are polymorphic. for example: QAbstractItemModel::data and QWidget::event

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

        @VRonin
        Huh? What? I thought "polymorphic" meant the class is derived from two or more other classes?? So you would write something like:

        class One(Class_Two, Class_Three, ...)
        {
        }
        

        (remember I'm not C++, and my beloved C# although it allows interfaces only allows a class to be derived from one other class). That is what I was saying I do not see a lot of in Qt.

        I know what virtual is, but what is polymorphic about it??

        JKSHJ 1 Reply Last reply
        0
        • JonBJ JonB

          @VRonin
          Huh? What? I thought "polymorphic" meant the class is derived from two or more other classes?? So you would write something like:

          class One(Class_Two, Class_Three, ...)
          {
          }
          

          (remember I'm not C++, and my beloved C# although it allows interfaces only allows a class to be derived from one other class). That is what I was saying I do not see a lot of in Qt.

          I know what virtual is, but what is polymorphic about it??

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

          @JonB said in Strong typing problem:

          @VRonin
          Huh? What? I thought "polymorphic" meant the class is derived from two or more other classes?? ..... That is what I was saying I do not see a lot of in Qt.

          That's multiple inheritance. See https://doc.qt.io/qt-5/qwidget.html : Inherits: QObject and QPaintDevice

          I know what virtual is, but what is polymorphic about it??

          https://stackoverflow.com/questions/2835793/how-does-polymorphism-work-in-python

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

          JonBJ 1 Reply Last reply
          5
          • JKSHJ JKSH

            @JonB said in Strong typing problem:

            @VRonin
            Huh? What? I thought "polymorphic" meant the class is derived from two or more other classes?? ..... That is what I was saying I do not see a lot of in Qt.

            That's multiple inheritance. See https://doc.qt.io/qt-5/qwidget.html : Inherits: QObject and QPaintDevice

            I know what virtual is, but what is polymorphic about it??

            https://stackoverflow.com/questions/2835793/how-does-polymorphism-work-in-python

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

            @JKSH
            Ohhhhhhhhhhhhhhhhhh!!!

            I really thought the "poly" was the "multiple" in "multiple inheritance"...! I went to a talk about C++ multiple inheritance many years ago, and I really thought the guy used the "poly" word, either I'm mixing up or the lecture wasn't about what I thought it was :)

            OK, everything I said was about "multiple inheritance" not "polymorphism", so sorry. Yes, I see now QWidget is exactly what I had in mind, but there are not many other Qt classes which are multiple inheritors.

            kshegunovK 1 Reply Last reply
            1
            • JonBJ JonB

              @JKSH
              Ohhhhhhhhhhhhhhhhhh!!!

              I really thought the "poly" was the "multiple" in "multiple inheritance"...! I went to a talk about C++ multiple inheritance many years ago, and I really thought the guy used the "poly" word, either I'm mixing up or the lecture wasn't about what I thought it was :)

              OK, everything I said was about "multiple inheritance" not "polymorphism", so sorry. Yes, I see now QWidget is exactly what I had in mind, but there are not many other Qt classes which are multiple inheritors.

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

              @JonB said in Strong typing problem:

              but there are not many other Qt classes which

              Inheriting multiple classes from the same tree is frowned upon, and most of the time for good reason, because you'd have to do a virtual inheritance and ... well ... it gets complicated. Inheriting multiple classes is otherwise fine. Especially inheiriting classes that were made to be inherited - like those containing pure virtual functions - QIODevice, QAbstractView, QAbstractItemModel to name a few.

              Basically anything that has a virtual destructor is supposed to be inherited at some point ... and QObject has one.

              Read and abide by the Qt Code of Conduct

              JonBJ 1 Reply Last reply
              1
              • kshegunovK kshegunov

                @JonB said in Strong typing problem:

                but there are not many other Qt classes which

                Inheriting multiple classes from the same tree is frowned upon, and most of the time for good reason, because you'd have to do a virtual inheritance and ... well ... it gets complicated. Inheriting multiple classes is otherwise fine. Especially inheiriting classes that were made to be inherited - like those containing pure virtual functions - QIODevice, QAbstractView, QAbstractItemModel to name a few.

                Basically anything that has a virtual destructor is supposed to be inherited at some point ... and QObject has one.

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

                @kshegunov

                C# allows a class to inherit from only one class --- so it can only be one "kind of object" --- but you can add as many interfaces as you like to the inheritance. An interface is effectively a class with just a bunch of pure virtual functions, and nothing else (no variables). Neat, huh?

                kshegunovK 1 Reply Last reply
                0
                • JonBJ JonB

                  @kshegunov

                  C# allows a class to inherit from only one class --- so it can only be one "kind of object" --- but you can add as many interfaces as you like to the inheritance. An interface is effectively a class with just a bunch of pure virtual functions, and nothing else (no variables). Neat, huh?

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

                  @JonB said in Strong typing problem:

                  An interface is effectively a class with just a bunch of pure virtual functions, and nothing else (no variables). Neat, huh?

                  C# is similar to Java in that regard. And yeah, we call that interface in C++ too - an abstract class with no implementations.

                  But then I also like the fact that if my farm animal is both a horse and a transportation device it can be both with C++, and not pretend that my transportation device has a horse ... or think of 100 reasons to say why a horse cannot be also a transportation device, thus needing to implement the transportation device's specifics for each horse, car, bicycle and helicopter. Neat, huh?

                  PS.
                  You're probably not aware of my beloved saying for this particular topic: C++ ain't Java.

                  Read and abide by the Qt Code of Conduct

                  JonBJ 1 Reply Last reply
                  2
                  • kshegunovK kshegunov

                    @JonB said in Strong typing problem:

                    An interface is effectively a class with just a bunch of pure virtual functions, and nothing else (no variables). Neat, huh?

                    C# is similar to Java in that regard. And yeah, we call that interface in C++ too - an abstract class with no implementations.

                    But then I also like the fact that if my farm animal is both a horse and a transportation device it can be both with C++, and not pretend that my transportation device has a horse ... or think of 100 reasons to say why a horse cannot be also a transportation device, thus needing to implement the transportation device's specifics for each horse, car, bicycle and helicopter. Neat, huh?

                    PS.
                    You're probably not aware of my beloved saying for this particular topic: C++ ain't Java.

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

                    @kshegunov

                    And yeah, we call that interface in C++ too - an abstract class with no implementations.

                    Yeah, but you don't actually have an interface keyword :)

                    if my farm animal is both a horse and a transportation device it can be both with C++

                    It isn't. It's a horse-animal, which happens to implement a transportation device interface. If you think it's a transportation device which happens to implement a horse interface, I can't help you :)

                    kshegunovK 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @kshegunov

                      And yeah, we call that interface in C++ too - an abstract class with no implementations.

                      Yeah, but you don't actually have an interface keyword :)

                      if my farm animal is both a horse and a transportation device it can be both with C++

                      It isn't. It's a horse-animal, which happens to implement a transportation device interface. If you think it's a transportation device which happens to implement a horse interface, I can't help you :)

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

                      @JonB said in Strong typing problem:

                      Yeah, but you don't actually have an interface keyword :)

                      Nope, we don't. But that's only because we like to write more with less typing ... efficiency you see ... ;)

                      It isn't. It's a horse-animal, which happens to implement a transportation device interface. If you think it's a transportation device which happens to implement a horse interface, I can't help you :)

                      Heheh, and I thought it's an animal that happens to have aggregated transportation device features ... damn, that's the franken-horse ...!

                      Read and abide by the 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