Solved Strong typing problem
-
@J.Hilk said in Strong typing problem:
@JKSH
I'm pretty sure, @JonB was being cheeky ;-)Sometime hard to tell in written form 😉
-
@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
orQObject
, 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? -
@JonB The methods tagged with
virtual
are polymorphic. for example: QAbstractItemModel::data and QWidget::event -
@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
interface
s 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?? -
@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
-
@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. -
@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. -
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
interface
s as you like to the inheritance. Aninterface
is effectively a class with just a bunch ofpure virtual
functions, and nothing else (no variables). Neat, huh? -
@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. -
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 :) -
@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 ...!