Re: Polymorphism at run-time
On Apr 27, 4:52 pm, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
tommo97 <tomm...@gmail.com> writes:
I am a relative novice to C++ and was wondering:
if I have a base class is it possible to recursively create
new derived classes from it "on the fly" at runtime? What I
mean is that each derived class will have it's own static
members which can be calculated from the base class using
various functions, but that the number and variation between
the derived class and the base class may (are) not known at
compile time.
For example an octree:
Base class is a node;
1st derived class is a root node, the next is derived from
this; 2nd - nth derived classes are nodes at the various
levels of the tree - these are derived from one-another;
(n+1)th derived class is the leaf and is derived from the
previous class.
Sorry if this makes no sense. If you have any idea even of
the correct posing of this question please let me know!
C++ doesn't allow you to do anything at run-time.
That's not quite true. All of the C++ implementations I know
support dynamic linking, so you can take the C++ code, compile
it to a dynamic object, and then load it. Not necessarily the
easiest thing in the world, but if you're only targetting a
specific system, and you know where the C++ compiler is
installed, it can be done.
If you really needed to create classes at run-time, you would
have to use a more powerful programming language, such as
Common Lisp.
Or Scheme, or any number of other languages. What this
basically means is that they have a compiler for the language as
part of their runtime. Given the complexities of C++, that
would make for a very heavy runtime.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34