Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!elroy.jpl.nasa.gov!usc!zaphod.mps.ohio-state.edu!maverick.ksu.ksu.edu!ux1.cso.uiuc.edu!milo.mcs.anl.gov!midway!msuinfo!buster.cps.msu.edu!bourd From: bourd@buster.cps.msu.edu (Robert Bourdeau) Newsgroups: comp.lang.c++ Subject: Re: asking an object for its type Message-ID: <1991Feb14.144331.28031@msuinfo.cl.msu.edu> Date: 14 Feb 91 14:43:31 GMT References: <23984@netcom.COM> Sender: news@msuinfo.cl.msu.edu Reply-To: bourd@buster.cps.msu.edu (Robert Bourdeau) Organization: Computer Science, Michigan State University, E. Lansing Lines: 51 In article <23984@netcom.COM>, aed@netcom.COM (Andrew Davidson) writes: |> Here is my problem, I have some processing that only applies for |> certain types of objects. If an object is not of the correct type I |> want to do some error stuff. |> |> The problem is how do I fiqure out what the type of the object is. I |> could return a string, ie provide an istype member function but then |> the calling function would have to |> know what the string is in advance, It also wont work with inheritance |> |> Thanks Andy Why not do what Borland did in their class library. There is a header file use by the Borland class library called clssname.h or something like that, I can't remember exactly. Anyway, it look something like typedef int classType #define objectClass 0 #define containerClass (objectClass+1) #define collectionClass (containerClass+1) and so on.... The isA() member function for the class Container would loook something like: class Container : Object { .... public: .... classType isA() { return containerClass; } .... }; I am not sure how this is so terribly different from what you are proposing above, except that it is more efficient. Nevertheless, this idea will work with inheritance (if I understand what you are stating your problem to be). --- Robert Bourdeau --- bourd@buster.cps.msu.edu --- Michigan State University