Originally Posted by
CornedBee
No, doesn't have anything to do with the issue.
ChaosEngine, what exactly do you mean by templated base class? That there is a template parameter which names the type on which special handling is taken?
not quite. It's a bit of an abuse of the type system really.
if we have a class hierarchy like this
Code:
template <typename T>
class Base
{
};
class D1 : public Base<short>
{
};
class D2 : public Base<int>
{
};
D1 and D2 have no inheritance relationship as Base<int> and Base<short> are essentially 2 different classes. I've actually soved it using a private "grandfather" class
Code:
template <typename T, typename U = void, typename Enable = void>
class MyTemplate
{
public:
static void DoStuff(void)
{
cout << "generic template: " << typeid(T).name() << endl;
}
};
class BaseBase {};
template <typename T>
class Base : private BaseBase
{
};
class Derived : public Base<short>
{
};
class D2 : public Base<int>
{
};
template <typename T>
class MyTemplate<T,
typename boost::enable_if<boost::is_base_of<BaseBase, T> >::type
>
{
public:
static void DoStuff(void)
{
cout << "base template: " << typeid(T).name() << endl;
}
};
int main()
{
MyTemplate<int>::DoStuff(); // OK - prints "generic template"
MyTemplate<Base<int> >::DoStuff(); // OK - prints "base template"
MyTemplate<Derived>::DoStuff(); // Woohoo! - prints "base template"
MyTemplate<D2>::DoStuff(); // Woohoo! - prints "base template"
}
it's a bit of a hack, but it works.
all this work is actually to define a metafunction to handle specialised Scalar math, but it works now. Thanks everyone, especially CornedBee.