When convert a void pointer to a specific type pointer, which casting symbol is better, static_cast or reinterpret_cast?
- by BugCreater
A beginner question with poor English:
Here I got a void* param and want to cast(or change) it to a specific type. But I don't know which "casting symbol" to use.
Either**static_cast** and reinterpret_cast works.
I want to know which one is better? which one does the Standard C++ recommend?
typedef struct
{
int a;
}A, *PA;
int foo(void* a) // the real type of a is A*
{
A* pA = static_cast<A*>(a); // or A* pA = reinterpret_cast<A*>(a);?
cout<<pA->a<<endl;
return 0;
}
Here I use
A* pA = static_cast(a);
or
A* pA = reinterpret_cast(a);
is more proper?