POV-Ray : Newsgroups : povray.programming : void pointer array problem : Re: void pointer array problem Server Time
28 Jul 2024 08:30:14 EDT (-0400)
  Re: void pointer array problem  
From: Thomas Willhalm
Date: 11 Jul 2002 10:45:58
Message: <3d2d9a26@news.povray.org>
Warp wrote:

> Thomas Willhalm <tho### [at] uni-konstanzde> wrote:
>> No, it doesn't. It's just that the thing is named "object" instead of
>> "void*". Furthermore, you are forced to use it, if you want to create
>> generic container classes.
> 
>   Firstly, what is so bad about having to inherit your classes from a
> common base class?
>   Secondly, no-one forces you to do so. You can make a more rational
>   design
> by creating your own base class, which has common things to all classes.

Sorry, when talking about _generic_container_classes_ I meant a class
like linked list, dynamic array, heap, hashtable, and so on, where the
type of the content is not known to the programmer of the container class.  

In C++, you can use templates to design them generic in the sense that the
coder of the container class does not have to know the type of objects
that are inserted while still ensuring at compile time that the same kind
of objects is inserted or returned. (In case you want to insert objects
of different type the right way to do it is of course - as you wrote -
to create a common base class.) 

In Java however, I don't know any other way than inserting and returning
objects of type "object". IMO this is as bad as inserting and returning
"void*". So you can avoid "object" in Java and "void*" in C++ if you
design the items that are inserted in your container, but you can't
avoid "object" if you don't.
 
Thomas


Post a reply to this message

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