Click here to Skip to main content
15,899,313 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: a very wierd problem Pin
Californian226-Dec-07 11:33
Californian226-Dec-07 11:33 
GeneralRe: a very wierd problem Pin
CPallini26-Dec-07 22:22
mveCPallini26-Dec-07 22:22 
GeneralRe: a very wierd problem Pin
Luc Pattyn26-Dec-07 16:41
sitebuilderLuc Pattyn26-Dec-07 16:41 
GeneralRe: a very wierd problem Pin
David Crow27-Dec-07 4:28
David Crow27-Dec-07 4:28 
GeneralReceiving data from ListBox in another program. Pin
int01h26-Dec-07 9:31
int01h26-Dec-07 9:31 
GeneralRe: Receiving data from ListBox in another program. Pin
CPallini26-Dec-07 10:55
mveCPallini26-Dec-07 10:55 
GeneralRe: Receiving data from ListBox in another program. Pin
Hamid_RT28-Dec-07 5:07
Hamid_RT28-Dec-07 5:07 
GeneralWhy it is not good code for constructor Pin
George_George26-Dec-07 3:09
George_George26-Dec-07 3:09 
Hello everyone,


Here is a sample from Dr. Dobb C++. In the analysis, the code is bad below.

But I do not think the code is bad,

1. if bad_alloc is thrown in new int[], we just catch it and write some log;
2. if there are any exception in B's constructor, we will also be in catch block and we could also write some log.

Why it is bad code? Any comments?

(I do not agree that there is resource leak, since if we met with bad_alloc in new int[], there is no memory allocated at all, so no root of memory/resource leak).


http://www.ddj.com/cpp/184401297

C::C(int)
try
   : B(new int[n]) // horrible!
{
   ...
}
catch(Error &e)
{
   
}



thanks in advance,
George
GeneralRe: Why it is not good code for constructor Pin
CPallini26-Dec-07 3:29
mveCPallini26-Dec-07 3:29 
GeneralRe: Why it is not good code for constructor Pin
George_George26-Dec-07 3:50
George_George26-Dec-07 3:50 
GeneralRe: Why it is not good code for constructor Pin
Sarath C26-Dec-07 4:09
Sarath C26-Dec-07 4:09 
GeneralRe: Why it is not good code for constructor Pin
George_George26-Dec-07 18:19
George_George26-Dec-07 18:19 
GeneralRe: Why it is not good code for constructor Pin
CPallini26-Dec-07 4:46
mveCPallini26-Dec-07 4:46 
GeneralRe: Why it is not good code for constructor Pin
George_George26-Dec-07 18:22
George_George26-Dec-07 18:22 
GeneralRe: Why it is not good code for constructor Pin
CPallini26-Dec-07 21:05
mveCPallini26-Dec-07 21:05 
GeneralRe: Why it is not good code for constructor Pin
George_George26-Dec-07 21:31
George_George26-Dec-07 21:31 
GeneralRe: Why it is not good code for constructor Pin
CPallini26-Dec-07 22:00
mveCPallini26-Dec-07 22:00 
GeneralRe: Why it is not good code for constructor Pin
George_George26-Dec-07 22:36
George_George26-Dec-07 22:36 
GeneralRe: Why it is not good code for constructor Pin
CPallini26-Dec-07 22:53
mveCPallini26-Dec-07 22:53 
GeneralRe: Why it is not good code for constructor Pin
George_George26-Dec-07 23:14
George_George26-Dec-07 23:14 
GeneralRe: Why it is not good code for constructor Pin
CPallini26-Dec-07 23:34
mveCPallini26-Dec-07 23:34 
GeneralRe: Why it is not good code for constructor Pin
George_George27-Dec-07 0:39
George_George27-Dec-07 0:39 
GeneralRe: Why it is not good code for constructor Pin
CPallini27-Dec-07 0:58
mveCPallini27-Dec-07 0:58 
GeneralRe: Why it is not good code for constructor Pin
George_George27-Dec-07 1:03
George_George27-Dec-07 1:03 
QuestionFile rename in UNICODE Pin
Ajay L D26-Dec-07 2:56
Ajay L D26-Dec-07 2:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.