Why can I assign a QObject* to a QObject?
问题 Consider the following code: #include <QObject> class A : public QObject { Q_OBJECT public: A(QObject* parent = 0) : QObject(parent) {} } int main() { A a = new A(); return 0; } Why can I assign an object of type A* to a variable of type A without the compiler (or runtime) complaining? 回答1: In this code, the constructor of A is used to convert an A* to an object of type A , instead of assigning it. In general the compiler is allowed to implicitly use a matching constructor as a conversion