Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the most dangerous feature of C++? [closed]

I've heard lots of times that phrase of Bjarne Stroustrup "C++ makes it harder to shoot yourself in the foot; but when you do, it takes off the whole leg" and I don't really know if it is as terrible as it sounds.

What's the worst thing that has ever happened to you (or more properly, to your software) while programming in C++? In which ways can it be more dangerous than say plain C, for example?

like image 681
fortran Avatar asked Jul 07 '09 17:07

fortran


3 Answers

The virtual destructor requirement is easy for new comers to miss (although I think most compilers are smart enough to point this one out).

like image 197
eduffy Avatar answered Oct 11 '22 19:10

eduffy


delete [] array;

can sometimes become

delete array;

in the hands of someone who doesn't know. Tracking that bug down can suck horribly, and doesn't happen when you're doing malloc and free.

like image 11
mmr Avatar answered Oct 15 '22 11:10

mmr


buffer overflows have to be the most dangerous things in both c and c++. This is also the reason that Microsoft announced that they have added memcpy() to their list of banned functions

multiple inheritance is another

like image 7
SQLMenace Avatar answered Oct 15 '22 09:10

SQLMenace