Exit Wiki

This page serves as documentation of C++ tips, hints, and gotchas we found during use of the language (and the Standard Library, et al).

WD Style and Design Considerations

Wilcox Development Solutions C++ Style Guidelines

C++ Compile Speed Tips & Design Considerations

Containers and Iterators

Standard Containers and Objects

Custom Iterators

Another guide to writing a custom iterator

Dr Dobb's: C++ Iterators

Examples of "standard" iterator usage

I always forget how to construct a for loop with iterators, but now here is an example snippet (by Tom Becker)

   1 
   2      for (vector<T>::iterator iter = myVectorVariable.begin(); iter != myVectorVariable.end(); ++iter)
   3      {
   4         ; //do stuff here. depending on what kind of std::container you are iterating over, iter could be different things
   5       }

Misc

Variable Argument Lists (in C)

Variable Argument Lists HOWTO

Singleton Pattern

CppSingletonPattern

Bitwise operation example

I always get these confused

   1 
   2     long avalue = 0xFFFFEEEE;
   3     printf("%x", avalue & 0x0000FFFF );
   4  --> EEEE

C++ Style Casts

An article on C++ cast operations in the ACM

However, above article has the following issues

  1. static_cast casts void* too (as long as void* points to a former object and you know/guess the type correctly) (Stroustrup Special Edition 15.4.2.1)
  2. const_casts are only guaranteed if the variable was non-const to begin with: (Stroustrup Special Ed 15.4.2.1 / 10.2.7.1)
  3. dynamic_cast does NOT cast void* to a (pointer) object (Stroustrup Special Ed 15.4.2.1). I got a nice GCC compile error when I tried). The article does get it right that you can cast a (pointer) object to void* to tell if the type is polymorphic or not. (Stroustrup 15.4.1)
  4. dynamic_cast does NOT throw a Bad_cast exception if you pass it a reference - it throws a bad_cast exception.
  5. should have explicitly stated that reinterpret_cast is only guaranteed to work if the result type is the type used to define the value the value involved AND that the result has the exact same bit pattern as its argument. (Stroustrup 6.2.7)

(See Stroustrup's reasoning on why C++ casts exist)

converting char* to wstring

Cpp Information (last edited 2009-12-06 16:24:58 by RyanWilcox)