On Dec 7, 7:54 pm, StephQ <askmeo...@mailinator.comwrote:
StephQ doesn't seem to want to call the function if it's defined in
one of the base classes of the 'D' type (inside the 'Base' template).
Of course I may have misunderstood.
V
See my last reply. Basically for a given tag (say tag::mu) I want to
select set_obj( .., tag::mu) searching first in Derived, and then if
not present in all the bases of Derived. Obviously I am perfectly fine
with getting an error if two ore more candidates are present.
But I can not get this working with this implementation.
Thank you for your replies.
Best Regards
StephQ
Hi,
IMHO, try avoiding MI. Check the following.
Regards,
Francesco
namespace tag
{
struct mu {};
struct sigma {};
}
template< typename TBridge >
struct CBridger : TBridge {};
template< >
struct CBridger< void {};
//template<class D>
template<class D, typename TBridge = void >
//struct par
struct par : CBridger< TBridge >
{
template<class A1>
void set( const A1& a1 )
{
typedef typename A1::key_type tag1;
static_cast<D*>( this )->set_obj( a1, tag1() );
}
template<class A>
void set_obj( const A& a, tag::mu )
{
}
template<class A>
void set_obj( const A& a, tag::sigma )
{
}
};
struct muvar
{
typedef tag::mu key_type;
};
struct sigmavar
{
typedef tag::sigma key_type;
};
class Base : public par<Base>
{
public:
using par<Base>::set;
};
//class Derived : public par<Derived>, public Base
class Derived : public par<Derived, Base >
{
public:
//template<class A>
//void set_obj( const A& a, tag::mu )
//{
//}
template<class A>
void set_obj( const A& a, tag::sigma )
{
}
using par<Derived, Base>::set;
using par<Derived, Base >::set_obj;
};
int main()
{
Derived derived;
derived.set( muvar() );
}