By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,159 Members | 899 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,159 IT Pros & Developers. It's quick & easy.

optional inhertiance with templates

P: n/a
I have a question regarding "optional" inheritance in regards to template.
This is not compiled code.

template<typename T, typename P1 = Invalid<1>, typename P2 = Invalid<2>,
typename P3 = Invalid<3> >
class Mgr : public T,
public virtual Mgmt<P1>,
public virtual Mgmt<P2>,
public virtual Mgmt<P3>
{
public:
// .....
};

Now if the user sends the following:
class Mgr1;
class My1;
class My2;

Mgr<Mgr1, My1> MyMgr1; // I want the Mgr template to inherit from Mgr1 and
Mgmt<My1>, not Mgmt<Invalid<2>> or
Mgmt<Invalid<3>>

Mgr<Mgr1, My1, My2> MyMgr2; // I want the Mgr template to inherit from Mgr1,
Mgmt<My1>, and Mgmt<My2>, not Mgmt<Invalid<3> >

Is this possible to that?

Thanks.
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
skscpp wrote in news:3a**************************@posting.google.c om:
I have a question regarding "optional" inheritance in regards to
template. This is not compiled code.

template<typename T, typename P1 = Invalid<1>, typename P2 =
Invalid<2>, typename P3 = Invalid<3> >
class Mgr : public T,
public virtual Mgmt<P1>,
public virtual Mgmt<P2>,
public virtual Mgmt<P3>
{
public:
// .....
};

Now if the user sends the following:
class Mgr1;
class My1;
class My2;

Mgr<Mgr1, My1> MyMgr1; // I want the Mgr template to inherit from Mgr1
and Mgmt<My1>, not Mgmt<Invalid<2>> or
Mgmt<Invalid<3>>

Mgr<Mgr1, My1, My2> MyMgr2; // I want the Mgr template to inherit from
Mgr1, Mgmt<My1>, and Mgmt<My2>, not Mgmt<Invalid<3> >

Is this possible to that?

Typed into newsreader ...

struct invalid {};

template<
typename T,
typename P1 = invalid,
typename P2 = invalid ,
typename P3 = invalid struct manage_base : T, P1, P2, P3
{
};

template<
typename T struct manage_base< T, invalid, invalid, invalid > : T
{
};

template<
typename T, typename P2 struct manage_base< T, P2, invalid, invalid > : T, P2
{
};

// etc ...

template<
typename T,
typename P1 = invalid,
typename P2 = invalid,
typename P3 = invalid

class Mgr : public manage_base< T, P1, P2, P3 >
{
// some code ??
};

If for some reason you want to have Mgr inherit directly from
T, P1 ... then you'll have to specialize Mgr directly.

HTH

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.