delorie.com/archives/browse.cgi | search |
From: | "Jesper Lund" <jl1204 AT worldonline DOT dk> |
Newsgroups: | comp.os.msdos.djgpp |
References: | <Pine DOT SUN DOT 3 DOT 91 DOT 1010910090923 DOT 18194E-100000 AT is> <003201c13a3f$053b2f40$aa7ba8c0 AT fuego> |
Subject: | Re: Can You help me about djgpp with c++ |
Lines: | 71 |
X-Priority: | 3 |
X-MSMail-Priority: | Normal |
X-Newsreader: | Microsoft Outlook Express 5.00.2615.200 |
X-MimeOLE: | Produced By Microsoft MimeOLE V5.00.2615.200 |
Message-ID: | <5Bbn7.6249$9V5.360511@news000.worldonline.dk> |
Date: | Tue, 11 Sep 2001 00:58:08 +0200 |
NNTP-Posting-Host: | 213.237.1.108 |
X-Complaints-To: | news-abuse AT wol DOT dk |
X-Trace: | news000.worldonline.dk 1000162753 213.237.1.108 (Tue, 11 Sep 2001 00:59:13 MET DST) |
NNTP-Posting-Date: | Tue, 11 Sep 2001 00:59:13 MET DST |
Organization: | Customer of Tiscali A/S (World Online) |
To: | djgpp AT delorie DOT com |
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Reply-To: | djgpp AT delorie DOT com |
Gorden <gorden AT ms9 DOT url DOT com DOT tw> wrote in message news:003201c13a3f$053b2f40$aa7ba8c0 AT fuego... > I Buy a book (Teach Yourself C++, 3rd Edition By Herbert Schildt) inside > have a C++ smaple > > #include <iostream.h> > #include <conio.h> > > class samp > { > private: > int i; > > public: > samp(void) { cout << "constructor" << '\n'; } > ~samp(void) { cout << "destructor " << '\n'; } > void set(int n) { i = n ; } > int get(void ) { return i; } > > }; > > int test(samp o) > { > return o.get() * o.get(); > } > > void main(void) > { > clrscr(); > > samp o; > o.set(10); > cout << test(o) << '\n'; > } > > The Book have result is > constructor > destructor > 100 > destructor > > in borland c++ 3.01 the result is > constructor > destructor > 100 > destructor > > But in djgpp the result is > constructor > destructor > 100 > destructor > destructor > > Why in djgpp 3 times call destructor, I try compile on borland C++ 3.01 have > 2 times call destructor > Is djgpp or gpp error ?????????? > Apparently, gcc makes TWO copies of your samp object when it is passed as a value argument to the test(samp o) function (and Borland only one). I don't think that the C++ standard guarantees that only one copy of your object is made in this situation (but I could be wrong here?). By the way, it seems that if you define your own copy constructor (instead of relying on the one generated implicitly by the C++ compiler), only one copy of the samp object is made.
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |