Pointer Container LibraryThe recommended usage pattern of the container classes are the same as the for normal standard containers.
ptr_vector, ptr_list and ptr_deque offer the programmer different complexity tradeoffs and should be used accordingly. ptr_vector is the type of sequence that should be used by default. ptr_list should be used when there are frequent insertions and deletions from the middle of the sequence and if the container is fairly large (eg. more than 100 elements). ptr_deque is the data structure of choice when most insertions and deletions take place at the beginning or at the end of the sequence. The special container ptr_array may be used when the size of the container is invariant and known at compile time.
An associative container supports unique keys if it may contain at most one element for each key. Otherwise, it supports equivalent keys. ptr_set and ptr_map support unique keys. ptr_multiset and ptr_multimap support equivalent keys.
Idiomtic Object-Oriented Programming in C++ looks a bit different from the way it is done in other languages. This is partly because C++ has both value and reference semantics, and partly because C++ is more flexible than other languages. Below is a list of recommendations that you are encouraged to follow:
The has the following advantages:
- It reduces coupling because you do not have to maintain or update state
- It helps you to avoid slicing
- It ensures you override the right function
You might also want to read the following articles:
This has the following advantages:
- It makes sure all calls to the virtual function always goes through one place in your code
- It enables you to check preconditions and postconditions inside the forwarding function
You might also want to read Herb Sutter's article Virtuality.
Having an abstact base class prevents slicing when the base class is involved, but it does not prevent it for classes further down the hierarchy. This is where boost::noncopyable is handy to use.
Navigate:
| copyright: | Thorsten Ottosen 2004-2005. |
|---|