$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [boost] typeof or similar
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2010-02-23 08:20:14
Steffen Roeber wrote:
> My preferred way would be something like a factory:
>
> class Factory
>
> {
>
> public:
>
> template <class T>
>
> static Base *createDerived<T>()
>
> {
>
> return new DerivedT<T>();
>
> }
>
> };
>
>
>
> But how can I tell the factory which type to be used.
>
> Base *derived = Factory::createDerived<sameAsBase> (base); //base is a Base
> *
You can't, since you lost that information.
Even if you stored a type identifier for T, you couldn't get the type
out of it, all you can do is call a function depending on that type
identifier.
> But Boost has some
> methods that by-pass some language constraints. I took a loot at something
> like 'typeof'.
typeof gives the static type of an object has deduced by the compiler,
not the dynamic type.
So it's useless in your case.