Hi Gang,
The following code does not compile, but I can't figure out why. The
compiler complains that the CuriouslyDerive dType (CRDerived) does not
publish the "value_type ", yet in fact the class CRDerived does.
Is there any way of making the code work? I would like functions to
accept a CRBase template, and the CRBase must be able to deduce the
"value_type " of the function that it is "curiously calling".
Thanks.
Martin
------snip here 8< ------
template <typename CurioslyDerived Type>
struct CRBase
{
typedef typename CurioslyDerived Type::value_typ e value_type;
const CurioslyDerived Type& derived() const
{
return static_cast<con st CurioslyDerived Type&>(*this);
}
value_type invoke() const
{
return derived().foo() ;
}
};
struct CRDerived:
public CRBase< CRDerived >
{
typedef int value_type;
int foo() const
{
return 1234;
}
};
template <typename CurioslyDerived Type>
typename CRBase<Curiosly DerivedType>::v alue_type
invoke(const CRBase<Curiosly DerivedType>& c)
{
return cr.invoke();
}
int main()
{
CRDerived c;
int result = invoke(c);
return 0;
}
------snip here 8< ------
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]