1. Contents 1.1. Dynamic expressions template 1.2. Dynamic classes |
1.2.1. papa.cc (example of a dynamic class) 2. Copying 3. Downloading |
dyn<int> a,b,c; a = 5; b = 2; c = a+b; b = 4; cout << c;And get 9 as result instead of 7.
cout << c
does not current work
for safety reasons. cout << c.value()
does.)
proteus:~/src/dyn$ ./dyntest Loading lib './libmama.so' Loading sym 'Mama' Loading sym 'Baby' Loading lib './libpapa.so' Loading sym 'Papa' Testing Papa. Papa comes. Papa waves. Papa goes. Unloading sym 'Papa' Unloading lib './libpapa.so' (it is no longer in use) Getting 'Baby' Baby comes. Baby waves its hand happily. Baby goes. Unloading sym 'Baby' Getting 'Mama' Mama comes. Mama waves. Mama goes. Unloading sym 'Mama' Unloading sym 'Mama' Unloading sym 'Baby' Unloading lib './libmama.so' (it is no longer in use)(Papa, Mama and Baby are derived types from Thing-class, which is the only thing the dyntest executable knows of.)
This dynlib thing has been designed to be used fairly easily
without much needed changes to get it working. Here's the papa.cc
as an example (BASETYPE_THING
is defined in thing.hh,
and describes the base type of the class for the loader):
#include <cstdio> #include "thing.hh" class Papa : public Thing { public: Papa() { std::printf(" Papa comes.\n"); } virtual ~Papa() { std::printf(" Papa goes.\n"); } virtual void Wave() { std::printf(" Papa waves.\n"); } }; #include "dynlib.hh" static void *newpapa(void) { return new Papa; } dyncontent contents[] = { { BASETYPE_THING, "Papa", newpapa }, { 0, NULL, NULL } };
* No warranty. You are free to modify this source and to
* distribute the modified sources, as long as you keep the
* existing copyright messages intact and as long as you
* remember to add your own copyright markings.
* You are not allowed to distribute the program or modified versions
* of the program without including the source code (or a reference to
* the publicly available source) and this notice with it.
Generated from
progdesc.php
(last updated: Fri, 18 Oct 2002 22:37:54 +0300)
with docmaker.php
(last updated: Tue, 13 Aug 2002 14:17:29 +0300)
at Fri, 18 Oct 2002 22:38:20 +0300