Xref: news2.mv.net comp.os.msdos.djgpp:5067 From: Erik Max Francis Newsgroups: comp.os.msdos.djgpp Subject: Re: Q: How to check if two objects are of the same class (C++) ? Date: Sun, 16 Jun 1996 19:47:07 -0700 Organization: Alcyone Systems Lines: 42 Message-ID: <31C4C72B.5A3A9D98@alcyone.com> References: <31C4486F DOT 5607 AT ida DOT utb DOT hb DOT se> NNTP-Posting-Host: newton.alcyone.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Christian Axbrink wrote: > a) How to check if two objects (or object pointers) are of the same > class, and, wich should be evident from this question, First you should ask yourself why you're doing this. The idea of C++ having virtual member functions generally eliminates the need for this sort of behavior; that's the whole reason for having inheritance. Having said that you're probably going about it the wrong way, there are two easy ways to get what you want. The first is to use RTTI, which unfortunately, I don't know offhand whether or not g++ 2.7.2 supports. The second is to basically have _all_ of the required classes inherit from some identification class, who simply returns an integer (or enum value) telling what class it belongs to. Then, since all of the necessary classes will derive from this class, you can call a member function in this superclass to report the class, and then compare the two with the equality operator. There are also a few other ways, which involve features inherent in the C++ 2.1 spec. I don't think g++ 2.7.2 is compliant with the current spec yet, so they're probably not worth going into. > b) where I can find online documents describing C++ in some detail, not > just overviews and descriptions of the class libraries but all of the > operators and other fun stuff. I strongly suggest you get a C++ book. There are many good ones available, but the "best one" is really a matter of opinion. Go to your nearest computer bookstore and look through the C++ shelf. You're certain to find something that you like. > I have Turbo C/C++ by Herbert Schildt. This is not generally considered a very good book on C++. -- Erik Max Francis &tSftDotIotE && http://www.alcyone.com/max && max AT alcyone DOT com San Jose, California, U.S.A. && 37 20 07 N 121 53 38 W && the 4th R is respect H.3`S,3,P,3$S,#$Q,C`Q,3,P,3$S,#$Q,3`Q,3,P,C$Q,#(Q.#`-"C`- && 1love && folasade Omnia quia sunt, lumina sunt. && Dominion, GIGO, GOOGOL, Omega, Psi, Strategem "Out from his breast/his soul went to seek/the doom of the just." -- _Beowulf_