From -4804488732342519229
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,24c0140d54165625
X-Google-Attributes: gidf78e5,public
From: AllanW@my-dejanews.com
Subject: Re: a question about temporary exception object
Date: 1998/11/07
Message-ID: <71vr8l$qfm$1@nnrp1.dejanews.com>#1/1
X-Deja-AN: 409368974
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
References: <3642A62C.CF2FC315@ccnet.com>
X-Snookums: I love you
X-Original-Date: Fri, 06 Nov 1998 21:55:33 GMT
X-Http-User-Agent: Mozilla/4.06 [en] (Win95; U)
X-Http-Proxy: 1.0 x8.dejanews.com:80 (Squid/1.1.22) for client 199.125.171.8
Organization: Deja News - The Leader in Internet Discussion
X-Article-Creation-Date: Fri Nov 06 21:55:33 1998 GMT
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUANkRmeuEDnX0m9pzZAQG6vQF/aq5wwMxZC9GJ42o5xECvTMt0bL5XLUAE Xbrj8rcP+C0EYz2xAoUBeJgTE3ApaYia =tnPV
Newsgroups: comp.std.c++

In article <3642A62C.CF2FC315@ccnet.com>,
  Gilbert Chang <gchang@ccnet.com> wrote:

> // class Foo
> // {
> // public:
> //     Foo();

ADD:     Foo(const Foo&);

> //    ~Foo();
> // };
> //
>
> try
> {
>     throw Foo();
> }
> catch(Foo & foo)
> {
> }
>
> VS.
>
> try
> {
>     throw Foo();
> }
> catch(Foo foo)
> {
> }
>
> 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?

Give Foo a copy constructor, as shown above. The default
constructor was called once, the copy constructor was called
once, and both copies were eventually destructed. This is
correct behavior.

As a rule of thumb, always assume you've made a mistake before
you blame the compiler. There are exceptions to that rule, of
course, but the assumption is the safe way to go.

--
AllanW@my-dejanews.com is a "Spam Magnet" -- never read.
Please reply in USENET only, sorry.

-----------== 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              ]



