C++ Programming Gotchas

I normally act as mentor for more junior developers. Most of them are new to C, to C++ or to both of them. There are lot's of things to watch out for. Here are some things that burned somebody around me. C++ is a complex language, which means I am not really sure if it's their fault. If you take a look at some C++ guidelines (see Lakos' Large Scale C++), most of them are lists of language features that you shouldn't be using.

At the bottom of the file is a list of recommendations that I derived from my experiences.

Syntactic Gotchas

Calling a function without using parens

if (a >b)
You aren't calling the function. UpdateValues; without parens returns the address of the function instead of calling it. It is equivalent to

Semicolon trouble

while (a >b);
  // Do something...

!= vs =!

while (a =! -1)
  // Do something...

Semantic Gotchas

Conclusions I extracted