No.
The first one is a declaration and declares someVoidPtr to be a pointer to type T.
This line can exist on it's own.
the second one is a cast and creates a temporary variable of pointer to T (an L value) from the existing pointer someVoidPtr
So this line cannot stand on it's own - the variable being casted must already been declared.
My brain just melt down. Why typedef makes difference in this example? pT is still T* not T, right?
There must be something behind-scene that i don't see.
It probalby has to do with operator precedence and ambiguity issues.
consider this:
1 2 3 4 5 6 7 8 9 10
double val = 6.2;
double* pd = &val;
// look at the following:
(int*)(pd); // clearly casting pd to an int*
(int)(*pd); // clearly dereferencing pd to get a double, then casting the double to an int
// take away the parenethesis and all of the sudden it's not clear:
int * pd; // ?? wtf? Looks more like you're declaring a pointer, rather than casting
int *(pd); // ?? wtf? same
The thing that makes it ambiguous is the * operator.
T(foo) is a valid cast, but T*(foo) is not because it's ambiguous, as illustrated above.
The typedef here eliminates the need for the * operator, therefore removes the ambiguity.
typedef allows you to define a type that is equal to another already defined type, just an alias. It is not like a #define statement in that it is handled by the compiler and not the preprocessor. If you typedef int as Number, then the compiler recognizes Number as an alias for an int; it does not actually replace the text Number with int.
In C++, because of the multiple uses of the asterisk *, trying to cast without parenthesis like that confuses the compiler. Using typedef creates an alias for it, and so the syntax is no longer confusing and clearly a cast.