You should use reinterpret_cast
for casting pointers, i.e.
r = reinterpret_cast<int*>(p);
Of course this makes no sense,
unless you want take a int
-level look at a double
! You'll get some weird output and I don't think this is what you intended. If you want to cast the value pointed to by p
to an int
then,
*r = static_cast<int>(*p);
Also, r
is not allocated so you can do one of the following:
int *r = new int(0);
*r = static_cast<int>(*p);
std::cout << *r << std::endl;
Or
int r = 0;
r = static_cast<int>(*p);
std::cout << r << std::endl;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…