Path: utzoo!attcan!uunet!snorkelwacker!usc!samsung!munnari.oz.au!sirius.ucs.adelaide.edu.au!sirius!matthew From: matthew@cs.ua.oz.au (Matthew Donaldson) Newsgroups: comp.lang.c++ Subject: Destructors and arrays Message-ID: Date: 3 Aug 90 14:06:20 GMT Sender: news@ucs.adelaide.edu.au Distribution: comp Organization: Computer Science, Adelaide University, Australia Lines: 45 I have had some rather strange behaviour from AT&T C++ 2.0 when dynamically allocating and freeing arrays of classes. When newing an array of classes, the constructor is called for each element created, but when deleteing the array, only one destructor is called. Everything works as expected, however, if I declare an array on the stack. Here is the code I used: class X { public: X() { puts("Construct"); } ~X(){ puts("Destruct"); } }; main() { X *Ar= new X[10]; delete Ar; } ( Prints 10 "Construct" and 1 "Destruct" ) If I replace main with: main() { X Ar[10]; } I get 10 "construct" and 10 "destruct". Is this the way it is supposed to work, or am I doing something wrong? Thanks in advance, Matthew -- ------- Matthew Donaldson matthew@cs.ua.oz.au Operating Systems Group Computer Science Department University of Adelaide