I need some samples of bad C++ code that will illustrate violation of good practices. I wanted to come up with my own examples, but I am having a hard time coming up with examples that are not contrived, and where a trap is not immediately obvious (it's harder than it seems).
Examples would be something like:
- Not defining copy constructor for classes with
std::auto_ptr
members, and usingstd::auto_ptr
members with forward-declared classes. - Calling virtual functions from a constructor or a destructor (directly or indirectly).
- Overloading a template function.
- Circular references with
boost::shared_ptr
. - Slicing.
- Throwing exceptions from C callbacks (directly or indirectly).
- Floating point comparison for equality.
- Exception safety of constructors with raw pointer members.
- Throwing from destructors.
- Integer overflow when compiled on different architectures (mismatch of
size_t
andint
). - Invalidating a container iterator.
...or any other evil thing you can think of.
I'd appreciate some pointers to existing resources, or a sample or two.