I’ve just started working on a new codebase where each class contains a shared_ptr typedef (similar to this) like:
typedef boost::shared_ptr<MyClass> Ptr;
Is the only purpose to save typing boost::shared_ptr?
If that is the case, is the only reason not to do
#define Ptr boost::shared_ptr
in one common header the general problems with #define? Then you can do:
Ptr<MyClass> myClass(new MyClass);
which is no more typing than
MyClass::Ptr myClass(new MyClass);
and saves the Ptr definition in each class.
A macro (#define) is always defined globally.
This means that every use of the ‘string’ Ptr (even a variable) will be replaced by the macro.
The typedef can be placed in a class, in a namespace, … so you have much better control over it.
EDIT:
another advantage is that you can haver different Ptr types in different classes, e.g.
If these classes are then used in templated code, you can use T::Ptr as a type of pointer to the class, and the template will use the most-appropriate pointer for the class.