Boost logo

Boost :

From: Marco Costalba (mcostalba_at_[hidden])
Date: 2007-09-18 11:07:49


On 9/18/07, Stephen Torri <storri_at_[hidden]> wrote:
>
> This is more than enough to get started. I hope I have been clear. If
> not please ask me questions.
>

The 'components' in your factory are wrappers around default
constructor, i.e. they take no arguments (this is a great way to
simplify all the stuff ;-)

So in this case a simple template could be enough:

template<class T>
static T* def_ctor_wrapper() { return new T(); }

and you can instantiate it where you need without replicating all the
'Component* Create()' stuff inside each object.

If you plan to support more then default c'tors, i.e if you plan to
support passing arguments to your Create() functions probably you need
to reconsider all the design, and complicate it a bit BTW ;-)

I have sent to this mailing list a couple of weeks ago some examples
of a factory that does this (and much more) in case you are
interested.

Original posted factory uses pure C++ with no libraries, I'm now
converting it to use boost::fusion, just a way to learn myself this
nice library.

Marco


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk