Prev: U++ 1952 released
Next: Using vs. typedef
From: pfultz2 on 26 Jan 2010 05:19 Now, say for instance I have a class like this: class foo { public: virtual bool check() = 0; } template<class T, class U> class foo_impl : public foo { virtual bool check() { } } Now, i want to instantiate foo in two phases, first when i know what type T is, and then again when i know what type U is. Well if i use a generic factory to create it i get this: class factory { public: virtual foo * create() = 0; } I create a special factory when i know what type T is, but i really need to use templated virtual: template<class T> class factory_t { public: template<class U> virtual foo * create() { return new foo_impl<T, U>(); } } What i would like to do is pass the factory through to an interface like this: class bar { virtual void use(factory * f) = 0; } template<class U> class bar_impl { virtual void use(factory * f) { foo * x = f->create<U>(); //Of course not possible } } And of course this wont work. So instead maybe i could use two factories, the first one would keep the type T, and the second one would keep type U: template<class T> class first_factory { public: virtual factory * create() { } } template<class U> class second_factory { public: virtual factory * create() { } } Hopefully this makes sense, i just need a way to put the two factories together, maybe its not possible. Does anyone have any ideas? Maybe a different approach? -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
|
Pages: 1 Prev: U++ 1952 released Next: Using vs. typedef |