When convert a void pointer to a specific type pointer, which casting symbol is better, static_cast or reinterpret_cast?
Posted
by
BugCreater
on Stack Overflow
See other posts from Stack Overflow
or by BugCreater
Published on 2011-02-16T07:22:26Z
Indexed on
2011/02/16
7:25 UTC
Read the original article
Hit count: 165
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?
© Stack Overflow or respective owner