|
|
Subscribe / Log in / New account

The coding standards are the least of your worries!

The coding standards are the least of your worries!

Posted Jun 1, 2010 17:04 UTC (Tue) by Ed_L. (guest, #24287)
In reply to: The coding standards are the least of your worries! by Ed_L.
Parent article: GCC begins move to C++

[Edit]
Yes, I meant the try block must surround the scope of any auto object whose constructor might throw. Certainly

C_Bar *pfoo;
try{
pfoo = new(C_Bar);
}catch(...){};

will work just fine. But I *like* auto objects....

And yes, if used an Init() method may return a status flag rather than throw an exception.


to post comments

The coding standards are the least of your worries!

Posted Jun 1, 2010 17:13 UTC (Tue) by Ed_L. (guest, #24287) [Link]

Or even

pfoo = new C_Bar();

(Its what I get for writing code fragments without a compiler...)

The coding standards are the least of your worries!

Posted Jun 2, 2010 18:27 UTC (Wed) by Cyberax (✭ supporter ✭, #52523) [Link]

This is exceedingly bad design. Any good C++ programmer will write:

std::auto_ptr<C_BAR> bar(new C_Bar());

...or something like it. It's exception- and leak-proof.

In one of my projects we had a 'no naked new' rule. So the result of EACH 'new' must be wrapped in a smart pointer (there were only a few carefully audited places where this policy was relaxed). Worked wonders.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds