Path: utzoo!attcan!uunet!snorkelwacker!apple!brutus.cs.uiuc.edu!psuvax1!rutgers!bpa!tci!kempf From: kempf@tci.bell-atl.com (Cory Kempf) Newsgroups: comp.lang.c++ Subject: Re^2: Is there a way to tell which derived class an object belongs to? Message-ID: <645@tci.bell-atl.com> Date: 1 Feb 90 21:08:55 GMT References: <2815@draken.nada.kth.se> <636@tci.bell-atl.com> <7722@chaph.usc.edu> Organization: Technology Concepts, Inc. Sudbury Mass. Lines: 32 jeenglis@nunki.usc.edu (Joe English) writes: >kempf@tci.bell-atl.com (Cory Kempf) writes: >>matsl@nada.kth.se (Mats Luthman) writes: >>>Is there any way you can tell which derived class an object belongs to >>>if it is pointed to by a pointer to its base class? [method involving using a virtual member function returning a unique constant for each class deleted] > The >solution above gives that same problem to the >programmer, who has more information than >the compiler, but still not enough to do it >correctly. You have to make sure that each >time you derive a new class you give it a >unique new ID; this isn't practical in many >cases. I fail to see why. All it takes is to put up a piece of paper. When you want to create a new class, look at the last number on the list. Add one to it. Write the name of the class next to it. How is this not practical? (especially considering that I am doing this -- ie it is in practice). If you want to use a more advanced method, store the contents of the paper on the computer. Write a program that, when given a class name, will return the next available class ID. +C -- Cory Kempf Technology Concepts phone: (508) 443-7311 x341 uucp: {anywhere}!uunet!tci!kempf, kempf@tci.bell-atl.com DISCLAIMER: TCI is not responsible for my opinions, nor I for theirs