"dwaach" <xb************ **@gmail.comwro te in message
news:11******** *************@h 48g2000cwc.goog legroups.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(co nst B& b)
{ return !! dynamic_cast<co nst D*>(&b); }
Usage example (using <fstream>):
bool isFileOutput(st d::ostream& o)
{
return isInstanceOf<st d::ofstream>(o) ;
}
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <
http://www.brainbench.com