Boost logo

Boost :

From: Roland Schwarz (roland.schwarz_at_[hidden])
Date: 2004-12-06 02:25:18

Edward Diener wrote:

>Yes, I am interested in it. It appears to provide a way to do reflection on
>a limited basis by using a name to create an object.
I am not sure if this really compares to "reflection" (and introspection?).
I am simply using a map std::map<std::string, boost::any >, where the any
part holds a pointer to a constructor function. The string on the other
side is
a composite of the class name and typeid(FN).name(), where FN is the
signature of the ctor function. If you think using the RTTI of C++ ==
reflection then your assumptions are correct.

> Hajo Kirchhoff in his
>LitWindow library also provides a way to do reflection based on names
>although I do not believe he has the ability which you have to dynamically
>create objects based on names.
I was not aware of this. Thank you for the pointer.

>The only nit I have to pick is calling your implementation a virtual
>constructor lib. I do not see where polymorphism comes into play in the
>actual construction of the objects from its name. Perhaps a "name
>constructor lib" would be more accurate.
Hmm, I was already considering this, but look at it a different way:
What is the sense of beeing able to construct an object of
which you do not know anything? You won't be able to call
a single function!
So you definitely need at least an abstract base class that
defines the common interfaces. And this is where polymorphism
comes into play. I would even say that the "covariant return types"
are at the core of my implementation. Now my implementation
allows to instantiate any derived class. This is why it is called
"virtual constructor". Also it is not me who coined this wording.
As I already mentioned I was reading Stroustrups book and
his explanation of the term "virtual constructor" inspired me
to my implementation. (But having it called dynamic_new
reflects your concerns a little I think.)


Boost list run by bdawes at, gregod at, cpdaniel at, john at