peter said:
A typedef'd pointer is as much a raw pointer as the real thing, and
the typedef has the sad property to obfuscate and complicate matters.
I must say that typedefs for pointers should be avoided in 99% of real
cases.
A typedef is a compile-time abstraction. The fact that it doesn't
impose run-time overhead doesn't make it any less valuable. If you
really want to criticize it, then ask why there isn't a "hard typedef"
that defines entirely new types, as well as the "soft typedef" used to
alias type names.
When you iterate over a std::vector<int>, how do you know whether to use
std::vector<int>::iterator, and when to avoid this typedef's "sad
property to obfuscate and complicate matters" by directly using int*?
Do you write separate code for platforms where
std::vector<int>::iterator has different implementations?
Which of the following alternatives provides more information to the reader:
int i;
int32 i;
Suppose you're using std::string to mean four different things.
Eventually, you decide to switch to a new type for one of those things,
but not the others. If you've been using typedefs to associate names
with your ideas, then you change code in exactly one place. Else, you
have to walk through every use of string and try to figure out whether
it's one of the uses that has to be updated. For example:
std::string employee_name;
std::string employee_id;
Is a lot less maintainable than:
typedef std::string name_type;
typedef std::string id_type;
name_type employee_name;
id_type employee_id;
If the IDs ever switch to a more heavy-weight type, e.g. one that
maintains invariant properties of employee IDs, you change only the
typedef in the latter case, but have to go digging through all the uses
of std::string to figure out which strings represent IDs.