Re: Constructors And Exceptions
From: Siemel Naran (SiemelNaran_at_REMOVE.att.net)
Date: 12/16/04
- Next message: Tim Bücker: "IWebBrowser2: Navigate2 ignored"
- Previous message: Jonathan Turkanis: "Re: is MS newer <iostream> is slower than older <iostream.h>?"
- In reply to: Kurt Krueckeberg: "Re: Constructors And Exceptions"
- Next in thread: Alf P. Steinbach: "Re: Constructors And Exceptions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 16 Dec 2004 04:41:57 GMT
"Kurt Krueckeberg" <kurtk@pobox.com> wrote in message
news:G8adnWKVLp2jP13cRVn-
> class Sample {
> public:
> Sample()
> {
> s_ = new char[5];
> throw;
> }
> private:
> auto_ptr<char *> s_; // destructor will free memory if
exception
> is thrown
> };
The type of s_ is like char**, so your could should not compile. Anyway,
even if you use auto_ptr<char>, the code will compile but it is not correct,
because one must use delete[] to delete arrays. I think the appropriate
container here is std::vector, though I think boost has an auto_ptr like
object that invokes delete[].
- Next message: Tim Bücker: "IWebBrowser2: Navigate2 ignored"
- Previous message: Jonathan Turkanis: "Re: is MS newer <iostream> is slower than older <iostream.h>?"
- In reply to: Kurt Krueckeberg: "Re: Constructors And Exceptions"
- Next in thread: Alf P. Steinbach: "Re: Constructors And Exceptions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|