I have the following problem:
class Base
{
};
class Derived : public Base
{
};
class Different
{
};
class X
{
public:
template
stat
You must use SFINAE for this. In the following code, the first function can be instantiated if and only if you pass something that can't be (implicitly) converted to Base *. The second function has this reversed.
You might want to read up on enable_if.
#include
#include
#include
class Base {};
class Derived : public Base {};
class Different {};
struct X
{
template
static typename boost::disable_if,
const char *>::type func(T *data)
{
return "Generic";
}
template
static typename boost::enable_if,
const char *>::type func(T *data)
{
return "Specific";
}
};
int main()
{
Derived derived;
Different different;
std::cout << "Derived: " << X::func(&derived) << std::endl;
std::cout << "Different: " << X::func(&different) << std::endl;
}