On 3/27/07, Scott Meyers <usenet@aristeia.com> wrote:
Given some base class,
class Base { virtual ~Base(){} };
I want to be able to implement this:
template<typename Seq> const Base& createObject() { // return an object that inherits from Base and every type in Seq }
The problem is how to create the type of object I want.
Thanks,
Scott
I'm probably won't use the correct mpl-isms, but something like template <typename Seq> struct inherit_all { struct type : public virtual first<Seq>::type, public virtual inherit_all<tail<Seq>::type>::type { }; }; assuming first<> and tail<> exist or are easily implementable. Then template <typename Seq> struct Base_and_Seq : public virtual Base, public virtual inherit_all<Seq>::type { };
template<typename Seq> const Base& createObject() { // return an object that inherits from Base and every type in Seq return new Base_and_Seq<Seq>(); }
Does any of that work, or at least head in the right direction? Or am I just recreating what inherit_linearly, etc already does? Tony