Victor Bazarov wrote:
Quote:
Originally Posted by
Miguel Guedes wrote:
Quote:
Originally Posted by
>I have template class definition like so:
>>
>template <typename Type>
>class Foo
>{
>.
>.
>template <typename SubTypeType* create();
>template <typename SubType, typename Param1Type* create();
>template <typename SubType, typename Param1, typename Param2Type*
>create(); .
>.
>
Seems like those functions are missing some arguments.
>
Quote:
Originally Posted by
>};
>>
>The aim is to allow Foo::create to instantiate any (Type) class and
>let it construct it with either no construction parameters, one or
>two.
>>
>Is there any way these three methods can be somehow simplified into
>one while keeping the same functionality?
>
Don't confuse simplification with reducing the number of member
functions.
>
Try implementing it to the best of your abilities. See what it leads
to. Then see if you can determine any commonality beween them, and
if you can, see if you can extract it into a separate function or
function template.
>
BTW, what is the point of having a generic factory like that? What
problem are you solving?
It's a factory that will do resource management of different polymorphic types,
each of which have different specializations. In other words, I'm developing a
factory for /Type/ types, which must support instantiation of any /Type/'s
/SubType/ types while allowing for up to 2 parameters to be passed in for
construction or none.
In all honesty, I started this thread thinking C++ allowed for template
parameters to be declared as optional. If it did, I'd only need _one_ create
method rather than three, hence my referring to the "simplification of the
methods into one" in my post.
I now realize how stupid that was. That's what you get when have too much
caffeine and not enough sleep I guess.
Thanks for your reply Victor and apologies for misleading you.
PS: After writing this I think I'm going to change Type and SubType to
BaseClass and InstantiateType, respectively, as it doesn't /really/ make much
sense.
--
Miguel Guedes
- X marks the spot for spammers. If you wish to get in touch with me by email,
remove the X from my address. -