Hello,
Here's my problem. I have a template function where I'd like to set a flag if the passed in data type is derived from a particular base class. The way to typically do this is to use dynamic_cast, unfortunately with PODs and non-polymorphic types coming I can't use the dynamic_cast.
Right now I have a work around that puts the responsibility on the programmer to know whether the input data type is derived from this class.
Any ideas?
Here's my problem. I have a template function where I'd like to set a flag if the passed in data type is derived from a particular base class. The way to typically do this is to use dynamic_cast, unfortunately with PODs and non-polymorphic types coming I can't use the dynamic_cast.
Right now I have a work around that puts the responsibility on the programmer to know whether the input data type is derived from this class.
Any ideas?
Code:
class Indexable
{
public:
virtual ~Indexable();
virtual void doSomething();
}
template <class T>
void myDesiredFunction(T *ptr)
{
if(dynamic_cast<Indexable*>(ptr))
{
// this is a data type derived from Indexable
}
else
{
// PODS, non-polymorphic, and classes not derived from Indexable
}
}
Comment