POV-Ray : Newsgroups : povray.general : CSDL: C-like Simulation Description Language : Re: CSDL alpha 1 release Server Time
7 Aug 2024 09:22:44 EDT (-0400)
  Re: CSDL alpha 1 release  
From: Thorsten Froehlich
Date: 23 Jan 2002 17:20:19
Message: <3c4f3723@news.povray.org>
In article <chr### [at] netplexaussieorg> , 
Christopher James Huff <chr### [at] maccom>  wrote:

> Having to duplicate essentially the same code for every subclass (for a
> Copy() function) just so I can make a copy of an object from a
> base-class pointer.

Well, while I admit the lack of this being available via the language can be
annoying in some cases, it is also important to not have a copy always
create something one didn't ask for.

And you don't need to duplicate any code at all.  Simply make your copy
function virtual.  That way by default the copy function of the subclass
will be called.  In that function simply write "return new SubClass(*this);"
and all your problems are gone.

> Having to return void pointers and cast them to the
> correct types. Mostly having what I can do with an object being
> determined by the type of pointer to it I have, instead of what the
> object can do.

Hmm, this really should not happen.  You can always avoid this problem with
a common base class.  Even if there are some problems in your class design
this at least allows you to not have to store void pointers, which is an
indication of some problem in the class design.  Try to get access to a copy
of "Design Patterns - Elements of Reusable Object-Oriented Software", it
illustrates some good designs.

> Templates.

Well, keep in mind that the most powerful feature of templates, the "export"
keyword is not supported in any compiler yet.  Once it will be available
templates have a potential far greater than what i.e. Java offers for
reusable containers.  Basically the export keyword has the power to
completely delegate the choice of code reuse to the compiler.  Current
compilers will duplicate a lot of similar code, and some will then hope for
the linker to cleanup the mess.  Of course, this way a lot of potential
using the available information for optimization is lost :-(

    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.