Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!rpi!uwm.edu!bionet!agate!ucbvax!dog.ee.lbl.gov!nosc!humu!humu.nosc.mil From: kent@humu.nosc.mil (Kent K. Kuriyama) Newsgroups: comp.lang.c++ Subject: Incorrect handling of destructors in Turbo C++ Keywords: Turbo C++, destructors Message-ID: <546@humu.NOSC.Mil> Date: 24 Mar 91 23:08:12 GMT Sender: kent@humu.NOSC.Mil Organization: Naval Ocean Systems Center, Hawaii Laboratory Lines: 57 There seems to be a bug in the code that Turbo C++ 1.00 generates. In the following program the destructor routine should only be called once. ------------ # include class A { protected: int i; public: A(); ~A(); }; A::A() { printf("Constructor called\n"); } A::~A() { printf("Destructor called\n"); } void sub(A a) { printf("in sub\n"); } void main() { A a; printf("before call\n"); sub(a); printf("after call\n"); } ------------ When this program is executed: ------------ Constructor called before call in sub after call Destructor called Destructor called ------------ Am I wrong to think that the destructor should only be called once? Kent Kuriyama Voice (808) 257-1618 Naval Ocean Systems Center FAX (808) 257-1685 Hawaii Laboratory Box 997, Code 531 kent@nosc.mil Kailua, HI 96734