If your class already uses std::vector<A*> typedef std::vector<A*>::size_type size_type in its implementation, then adding typedef std::vector<A*>::size_type size_type does not provide any details than it already provides.
However, if you intend to use full encapsulation, you would like to use a technique such as the idom PIMPL or the interface class (also known as the protocol class), completely hiding that std::vector<A*> <A *> is used in the implementation in general:
Before:
After (using the PIMPL technique):
class FooImpl; class Foo { public: typedef size_t size_type;
FooImpl is defined in the source file, not in the header, completely hiding the selection of the vector in the implementation details. Therefore, you no longer need the #include <vector> in your header file, which has several advantages:
- Users of your header file should not (indirectly) include a vector if they are not using it. This can improve compilation performance, which is important for larger codebases.
- If you change the implementation (for example, a list), you do not run the risk of breaking code that (mistakenly) relied on your
#include <vector> , which is now #include <list> . It happens.
source share