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

> In C++, if you have a derived object that implements a certain method
> not in its base class, but only have a base-class pointer to it, you
> can't call that method unless you cast to that type. It's a pain that
> produces ugly code, that's all. In Objective C, the methods you can call
> are determined by what the object itself responds to, at runtime, not by
> the type of pointer you have.

Not really.  dynamic_cast<> does exactly the same, with the only difference
that you have the choice of the object you actually want to respond.  It
protects you from getting a pointer to a base and then calling some method
by accident also you never wanted to call that method of that object.  In
C++ you are protected from this because you have to explicitly say _what_
you want rather than having the system take a guess and possibly giving you
something you never asked for.

Most important, dynamic_cast<> is fully type-safe, which seems to be what
you are missing.  Further, it is significantly more efficient because you
only do the dynamic casting once (by casting the first time you need to
access that particular object and storing the it in a local pointer of the
correct type), while in Objective C, for repeated calls to various functions
the compiler would have to employ (nearly) impossible analysis of the code
to turn it into just one call.  Thus it has to run the dynamic casting code
every time, which is extremely inefficient.

Apart from this, without dynamic_cast<>, multiple inheritance would be far
more difficult to use.

    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.