From -7159538654197689412
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,24c0140d54165625
X-Google-Attributes: gidf78e5,public
From: nimel@hem1.passagen.se
Subject: Re: a question about temporary exception object
Date: 1998/11/07
Message-ID: <721upr$eai$1@nnrp1.dejanews.com>#1/1
X-Deja-AN: 409443732
X-NNTP-Posting-Host: 159.72.248.201
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <3642A62C.CF2FC315@ccnet.com>
X-Http-User-Agent: Mozilla/4.5b2 [en] (WinNT; I)
X-Http-Proxy: 1.0 x8.dejanews.com:80 (Squid/1.1.22) for client 159.72.248.201
Organization: Deja News - The Leader in Internet Discussion
X-Article-Creation-Date: Sat Nov 07 17:08:10 1998 GMT
Newsgroups: comp.std.c++
Originator: clamage@taumet


In article <3642A62C.CF2FC315@ccnet.com>,
  Gilbert Chang <gchang@ccnet.com> wrote:
>
> According to the standard, the constructor and the destructor of Foo
> should be called exactly once for each in the first case, but they could
> be called either once for each or twice for each.  Is my understanding
> correct?
>
> I experimented with VC++6.0.  In both cases, the constructor was called
> once, but the destructor was called twice.  Did I do something wrong or
> is the compiler simply broken?

I tried the same thing on VC++ 6.0. For me both the constructor and
the destructor was called once when catching by reference, and
twice when catching by value. My guess is that you forgot to count
the copy constructor. Below is the output from my test:

begin
throwing Foo
Foo ctor
caught Foo&
Foo dtor
throwing Foo
Foo ctor
Foo copy ctor
caught Foo
Foo dtor
Foo dtor
end

/Niklas Mellin

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




