Home

D. Susman wrote:

>1)

No comment.

> 2)Should one check a pointer for NULL before deleting it? Although
> deleting a NULL pointer is said to be safe in C++, I see a lot of code
> doing the check before deletion. Is this because they still preserve
> the C attitude?

Yes, I used to do that prior to knowing that it is
safe to delete a NULL pointer. When I see this...

if( p != NULL ){ delete p; }

.... I usually believe that the programmer simply
did not know. But to be honest, nowadays
I never have deletes in my code. I've written
entire projects without calling delete once (because
its called automatically). I even to global searches
for delete to find the source of problems (as I've
spent many a late night because of pointers).

> 3) When is a struct favourable over a class?

I would guess for plain old data (no behaviour) or
when all the members can be public, for instance
in a traits or policy class, and you are too lazy to
type public...

> 4) Should one favor '++iterator' over 'iterator++'? I did some
> performance tests myself and did not see a big gap between their
> execution times ( by using containers with size 10000000 which contain
> objects )

While the possibility exists for things to be optimized,
especially in the case of built-in types, I prefer using ++iterator
consistently. Why pessimize prematurely?

Regards,

Werner

previous
next

Re: Try this
Re: What is going on here?
Re: Looping through File Question
Re: how to get output.
Re: Shed Skin Python-to-C++ compiler 0.0.23
Rodzic Po Ludzku
Dzieci Niczyje
Fundacja Sloneczko
Kidprotect
Fundacja Hobbit