POV-Ray : Newsgroups : povray.programming : void pointer array problem : Re: void pointer array problem Server Time
28 Jul 2024 08:27:43 EDT (-0400)
  Re: void pointer array problem  
From: Thorsten Froehlich
Date: 2 Jul 2002 10:11:53
Message: <3d21b4a9@news.povray.org>
In article <3d2194d3$1@news.povray.org> , "cadman" 
<REM### [at] povraycouk> wrote:

> Therein lies the problem.  I guess I forgot that part of the code:  location
> is of type (void *).  I want location (and all elements of the array) to be
> able to hold anything (pointer to a texture, an object, a vector,...).  MFC,
> of course, has untyped pointer collection classes, but I'm hoping for a
> certain degree of portability here...

Well, if you really, really want such a mess, this

    ((CMyObject *)(*location))=thing;

and/or this should work

    *location=(void*)thing;

depending on what you are really doing.

However, I strongly suggest you don't mess around with void pointers in such
a way.  The proper way is to inherit everything array can hold from a common
base class and let array point to those.

It is absolutely inappropriate to use void for what you try to do in C++ and
there is no excuse.  Of course, I know you will probably ignore this advice
and in a few weeks fight against constant crashes, but then don't ask how to
fix those -- you already know the answer now ;-)

    Thorsten

____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.