C++ (Qt)class A {public: ~A () { foreach (A *a, vector_) { delete a; } } void addChild (A *a) { vector_.push_back (a); }private: QVector <A*> vector_;} class B : public A { B (A *a = 0) { if (a) { a->addChild (this); } }}
C++ (Qt)c cc; a *pa = &cc;b *pb = &cc;c *pc = &cc; cc.point_to_b = pb; if (true && (void*) pa == (void*) pb && (void*) pb == (void*) pc && (void*) pc == (void*) pa && sizeof (a) == sizeof (pa->a_) + sizeof (pa->b_) + sizeof (pa->c_) + 3 /*hello alignment*/ && sizeof (a) == 12 /*hello 32 bit x86*/ && sizeof (b) == sizeof (a) + sizeof (pb->d_) + sizeof (pb->e_) + sizeof (pb->f_) /*a + b members*/ && sizeof (b) == 24 /*12 + 12*/ && sizeof (c) == 40 /*24 + 16, extra 4 for point_to_b*/ && (char *) &pc->a_ - (char *) pa == 0 && (char *) &pc->b_ - (char *) pa == 4 && (char *) &pc->c_ - (char *) pa == 8 && (char *) &pc->d_ - (char *) pa == 12 && (char *) &pc->e_ - (char *) pa == 16 && (char *) &pc->f_ - (char *) pa == 20 && (char *) &pc->g_ - (char *) pa == 24 && (char *) &pc->h_ - (char *) pa == 28 && (char *) &pc->i_ - (char *) pa == 32 && (char *) &pc->point_to_b - (char *) pa == 36 && (char *) pc->point_to_b - (char *) pa == 0) std::cout << "thank God, C++ is fine..\n";else{ std::cerr << "Alarm! something's wrong with C++!\n"; exit (1);}