delorie.com/archives/browse.cgi | search |
Mailing-List: | contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm |
List-Subscribe: | <mailto:cygwin-subscribe AT sources DOT redhat DOT com> |
List-Archive: | <http://sources.redhat.com/ml/cygwin/> |
List-Post: | <mailto:cygwin AT sources DOT redhat DOT com> |
List-Help: | <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs> |
Sender: | cygwin-owner AT sources DOT redhat DOT com |
Delivered-To: | mailing list cygwin AT sources DOT redhat DOT com |
Message-ID: | <001f01c178c0$5b315c20$4a5f37c1@isima.fr> |
Reply-To: | "Bruno Bachelet" <bachelet AT ifrance DOT com> |
From: | "Bruno Bachelet" <bachelet AT ifrance DOT com> |
To: | <cygwin AT cygwin DOT com> |
Subject: | Problem with virtual inheritance and destruction of arrays |
Date: | Thu, 29 Nov 2001 11:26:49 +0100 |
MIME-Version: | 1.0 |
X-Priority: | 3 |
X-MSMail-Priority: | Normal |
X-Mailer: | Microsoft Outlook Express 6.00.2600.0000 |
X-MimeOLE: | Produced By Microsoft MimeOLE V6.00.2600.0000 |
I apologize in advance if the bug has already been reported. Normally when calling the destructor of an object, the destructors of all the classes in the hierarchy of inheritance are executed. Imagine you have a virtual inheritance at some place in the hierarchy, the destruction works well with a single object, but it doesn't work with an array of objects. Here is an example I compiled with Cygwin 1.3.2 and Cygwin 1.3.5 using no particular optimization flag. #include <iostream.h> class A { protected: int i; public: A(int x=5) : i(x) {} public: virtual ~A(void) { cout << "A: i=" << i << endl; } }; class B : public A { protected: int j; public: B(int x=5) : A(10),j(x) {} public: virtual ~B(void) { cout << "B: j=" << j << endl; } }; class C : public virtual A { protected: int k; public: C(int x=5) : A(20),k(x) {} public: virtual ~C(void) { cout << "C: k=" << k << endl; } }; int main(void) { A * a = new A; B * b = new B; C * c = new C; A * ta = new A[3]; B * tb = new B[3]; C * tc = new C[3]; cout << "destruction object class A" << endl; delete a; cout << "destruction array class A" << endl; delete [] ta; cout << "destruction object class B : public A" << endl; delete b; cout << "destruction array class B : public A" << endl; delete [] tb; cout << "destruction object class C : public virtual A" << endl; delete c; cout << "destruction array class C : public virtual A" << endl; delete [] tc; return (0); } Here is the result that illustrates the point. Destruction of the array of objects of class C didn't execute correctly. destruction object class A A: i=5 destruction array class A A: i=5 A: i=5 A: i=5 destruction object class B : public A B: j=5 A: i=10 destruction array class B : public A B: j=5 A: i=10 B: j=5 A: i=10 B: j=5 A: i=10 destruction object class C : public virtual A C: k=5 A: i=20 destruction array class C : public virtual A C: k=5 C: k=5 C: k=5 Good luck and "bravo" for the excellent work. <><><><><><><><><><><><><><><><><><><><> Bruno Bachelet (PhD Student) LIMOS Laboratory ISIMA (Door B112) Complexe des Cezeaux BP 10125 - 63173 Aubiere Cedex France Phone: (33).4.73.40.50.44 Fax: (33).4.73.40.50.01 Cellular: (33).6.71.94.81.31 E-mail: bachelet AT ifrance DOT com Web: http://bruno.bachelet.net <><><><><><><><><><><><><><><><><><><><> -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |