"dwaach" <xb**************@gmail.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
: I am thinking about implementing isInstanceOf() in c.
: Any ideas ???
C has no built-in concept of classes or instances,
so the answer would depend on how you choose to emulate
that feature.
In C++, dynamic_cast can be used to find if an object
is of a given subclass. You could write isInstanceOf
as follows:
template<class D, class B>
bool isInstanceOf(const B& b)
{ return !! dynamic_cast<const D*>(&b); }
Usage example (using <fstream>):
bool isFileOutput(std::ostream& o)
{
return isInstanceOf<std::ofstream>(o);
}
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <
http://www.brainbench.com