If I understand right, the types are *not* "replaced" when typedef is
used.
It depends on what you mean by "replaced", but typedef does not
introduce a new type. In the example, when you use
DirectoryRef, it's exactly as if you'd used
support::PtrObject said:
also, typedef is fundamentally a different construct than macro
replacement.
Replacement occurs at a fundamentally different phase of
compilation. And of course, unlike macros, typedef's obey all
of the usual scope and hiding rules. (I'd like to see you
replace the typedef of value_type in the standard containers
with a #define.)
typedef int* foo; // foo is a typedef for int*
#define foo2 int* // foo2 is a macro for int*
foo a, b // same as int* a, int* b
foo2 a, b // same as int* a, int b
You don't even need to go so far:
const foo a ; // same as int* const
const foo2 b ; // same as int const*
(This is, BTW, the strongest argument I know for always putting
the const after what it modifies. Unless, of course, it is an
argument against typedef'ing derived types.)