POV-Ray : Newsgroups : povray.programming : Pass a POV object to a class : Re: Pass a POV object to a class Server Time
28 Jul 2024 12:22:09 EDT (-0400)
  Re: Pass a POV object to a class  
From: Thorsten Froehlich
Date: 14 Mar 2001 10:41:50
Message: <3aaf913e$1@news.povray.org>
In article <7p5uatkfp1lg0lluhftkg2ad9okphd814a@4ax.com> , Peter Popov 
<pet### [at] vipbg>  wrote:

> Lastly, a side question. Are there license-free, public-domain,
> cross-platform examples of polymorphic sorted lists, binary, quad- and
> oct-trees or should I make them myself?

You just use the "polymorphic reference type" - others might call it "a
pointer" :-)

Lets say you have something like this (abbreviated syntax):

  class Base;
  class Building : Base;
  class House : Building;
  class Tower : Building;
  class Garage : Building;

And you want to store all buildings, you just do:

  vector<Building *> buildings;

You can access individual objects in a type safe manner like this:

  House *house = dynamic_cast<House *>(buildings[3]);

If is was a House dynamic_cast returns a valid pointer to a House.  If
not, it return NULL.  Note that dynamic_cast throws exceptions if you
cast references.


     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.