Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!cica!sol.ctr.columbia.edu!emory!mephisto!ncsuvx!news From: rcb@ccpv1.ncsu.edu (Randy Buckland) Newsgroups: comp.lang.c++ Subject: Determining an object's class Message-ID: <1990Feb13.202006.29601@ncsuvx.ncsu.edu> Date: 13 Feb 90 20:20:06 GMT Sender: news@ncsuvx.ncsu.edu (USENET News System) Distribution: comp Organization: NCSU Computing Center Lines: 38 Is it possible in C++ to determine if an object is a member of a certain subclass? For example: ---------------------------------------------------------------------------- class foo { ... }; class bar : public foo { ... }; foo *aFunction (); code() { foo *a_foo; bar *a_bar; a_foo = aFunction(); /*********** Here's what I want to do **************/ if (is_class (a_foo, foo)) { ... } } ---------------------------------------------------------------------------- What I want to be able to do is to have an object that can contain a set of objects of type "foo" or one of it's subclasses. I will have operations that can be done to all members of the set and all classes based on "foo" will support. This I can do. However, I want to be able to extract an object from the set and if it is really a member of the subclass, call an extra method that only the subclass supports. I could brute force it with a variable/function that hold's the object type, but this seems wasteful. (Oh for a real, compiled, OO language on ultrix. Eiffel does not qualify since it break's every time I use it.) Randy Buckland rcb@ncsuvx.ncsu.edu