Just to provide some examples for the things said: STL containers.
typedef std::map<int,Froboz> tFrobozMap;
tFrobozMap frobozzes;
...
for(tFrobozMap::iterator it=frobozzes.begin(); it!=map.end(); ++it)
{
...
}
It is not unusual to even use typedefs like
typedef tFrobozMap::iterator tFrobozMapIter;
typedef tFrobozMap::const_iterator tFrobozMapCIter;
Another example: using shared pointers:
class Froboz;
typedef boost::shared_ptr<Froboz> FrobozPtr;
[update] As per comment - where to put them?
The last example - using shared_ptr - is easy: are true header material - or at least a forward header. You do need the forward declaration for shared_ptr anyway, and one of its declared advantages is that it's safe to use with a forward decl.
Put it another way: If there is a shared_ptr you probably should use the type only through a shared_ptr, so separating the declarations doesn't make much sense.
(Yes, xyzfwd.h is a pain. I'd use them only in hotspots - knowing that hotspots are hard to identify. Blame the C++ compile+link model...)
Container typedefs I usually use where the container variable is declared - e.g. locally for a local var, as class members when the actual container instance is a class member. This works well if the actual container type is an implementation detail - causing no additional dependency.
If they become part of a particular interface, they are declared together with the interface they are used with, e.g.
// FrobozMangler.h
#include "Froboz.h"
typedef std::map<int, Froboz> tFrobozMap;
void Mangle(tFrobozMap const & frobozzes);
That gets problematic when the type is a binding element between different interfaces - i.e. the same type is needed by multiple headers. Some solutions:
- declare it together with the contained type
(suitable for containers that are frequently used for this type)
- move them to a separate header
- move to a separate header, and make it a data class where the actual container is an implementation detail again
I agree that the two latter aren't that great, I'd use them only when I get into trouble (not proactively).