POV-Ray : Newsgroups : povray.binaries.programming : [C++] Question about reinterpret_cast<> : Re: [C++] Question about reinterpret_cast<> Server Time: 25 Jul 2008 15:15:10 GMT
  Re: [C++] Question about reinterpret_cast<>  
From: Mark Wagner
Date: 22 Nov 2001 05:35:22
Tim Chan wrote in message <3bfbf514$1@news.povray.org>...
>Hello, I'm studying C++ on my own and would appreciate some help.


[program snipped]

>I don't understand this line:
>
>****   print(reinterpret_cast<X*>(xp));  ****
>
>why do you pass 'xp' into the cast but not '&xp'....?

xp is of type pointer to int, and you are converting it to the type pointer
to X.  &xp would be the address of xp, and would be of type pointer to
pointer to int.

>Because earlier you need to pass the address of x into the cast:
>
>****  int* xp = reinterpret_cast<int*>(&x);  ****


Here, x is of type X.  &x is the memory address of x, and is of type pointer
to X.  The reinterpret_cast converts that to type pointer to int.

--
Mark


Post a reply to this message

Copyright 1991-2004 POV-Team™