POV-Ray : Newsgroups : povray.binaries.programming : [C++] Question about reinterpret_cast<> : Re: [C++] Question about reinterpret_cast<> Server Time
19 Apr 2024 15:56:31 EDT (-0400)
  Re: [C++] Question about reinterpret_cast<>  
From: Mark Wagner
Date: 22 Nov 2001 00:35:22
Message: <3bfc8e9a@news.povray.org>
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 2003-2023 Persistence of Vision Raytracer Pty. Ltd.