Article View: comp.sys.mac.oop.misc
Article #150Re: [Q] [enums] class_ID as enum is basically useless? Why not GetClassID()?
From: David Reiss
Date: Mon, 15 Jan 1996 22:28
Date: Mon, 15 Jan 1996 22:28
106 lines
4927 bytes
4927 bytes
The class_ID is meant to NOT be virtual...this way it can be used to
register the stream-constructor static routines with URegistrar allowing
easy construction using Constructor. I suppose a static GetClassID()
routine would be ok, but there's no real difference there. If you
want to do a
myPane->GetClassID()
kind of call, you should probably use RTTI (as far as I've been told) to
determine what kind of object your myPane is. As far as I know, there's
no other way, other than modifying the PP code itself.
-David
richard@moriarty.com (Richard Jason Lyders) wrote:
>HELP! Suggestions are MOST WELCOME!
>
>Why would someone use an enum for a class_ID in a class library? Why not
>simply provide a GetClassID() function for each class? That would be so
>much simpler and so much more useful!
>
>I don't seem to be able to use the enum class_ID to find out what class
>an object is because class_ID isn't "virtual" like a function. If you have
>an object of a class that is derived from a base class, and you are
>referencing that object using the base pointer, then class_ID does not
>tell you the class of the object, it tells you the class of the pointer.
>What god is this? I know what class the pointer is because I cast it
>myself! Duh?
>
>This means that I don't seem to be able to create a routine that uses a
>base class as a pointer to any of that base class's derived classes. . .
>because in that routine I need to know exactly what the class_id is of the
>REAL object rather than the class_ID of the base object (which is pretty
>darn obvious because it never changes).
>
>I did not expect to run into this problem. Is this a limitation? an error
>on my part? Is there another way to find out the actual class of an object
>without using a class_ID enum that really will give me the correct
>class_ID?
>
>So , by using an enum . . .whatever you type cast a pointer as. . . that's
>the class ID that you get. . . so it isn't any better than a compiler
>#define as far as I am trying to use it.
>
>If you check out my code example below. . .you will see my confusion as to
>why a class_ID enum would be used . . . and I hope ther is another way of
>finding out an object's actual class ID.
>
>PS: and no, it is not possible to give each class a GetClassID routine
>because I am having this problem with the Metrowerks PowerPlant class
>library and I don't think it is very acceptible to just go around
>changing the inner workings of a class library.
>
>class LPane {
> public:
> enum { class_ID = 'pane' };
> LPane() {};
> ~LPane() {};
>};
>
>class LView : public LPane {
> public:
> enum { class_ID = 'view' };
> LView() {};
> ~LView() {};
>};
>
>void main (void) {
> LPane aPane;
> LView aView;
> LPane * aPanePtr = &aPane;
> LView * aViewPtr = &aView;
> LPane * aPanePtr2 = (LPane*)aViewPtr;
>
> long aPaneClassID = aPanePtr->class_ID; // = 'pane' (obviously)
> long aViewClassID = aViewPtr->class_ID; // = 'view' (obviously)
> long aWhichClassID = aPanePtr2->class_ID; // = 'pane' ********* why?
>**********
>}
>
>/*
> ?
> ___ o _ _ /
>| o \ _ ___| |_ ___ _ _ _| | /"""\
>| /| | __) | o | '_| o | |~'~|
>|_|_\|_\___)_|_|_|_|_| \___| \ - /
>.---------------------------------^----.
>| Richard Jason Lyders Houston, Texas |
>| richard@moriarty.com |
>'-----------------------------OOo----oOO
> |=[]=|
> /_/\_\
> oOO OOo
>
>*/
>
> [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
> [ Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm ]
> [ Moderation policy: http://www.connobj.com/cpp/guide.htm ]
> [ Comments? mailto:c++-request@netlab.cs.rpi.edu ]
[ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
[ Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm ]
[ Moderation policy: http://www.connobj.com/cpp/guide.htm ]
[ Comments? mailto:c++-request@netlab.cs.rpi.edu ]
Technical Details
Message-ID:
<4dekdi$qs2@netlab.cs.rpi.edu>Path:
arc1-ca.pugleaf.net!library.erc.clarkson.edu!rpi!not-for-mailReferences:
<4dboiv$rlm@netlab.cs.rpi.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!library.erc.clarkson.edu!rpi!not-for-mail From: David Reiss <reiss@astro.washington.edu> Newsgroups: comp.sys.mac.oop.misc,comp.sys.mac.programmer.codewarrior,comp.lang.c++,comp.lang.c++.moderated Subject: Re: [Q] [enums] class_ID as enum is basically useless? Why not GetClassID()? Date: 15 Jan 1996 22:28:02 -0000 Organization: http://www.astro.washington.edu Sender: cppmods@netlab.cs.rpi.edu Approved: Dietmar.Kuehl@uni-konstanz.de Message-ID: <4dekdi$qs2@netlab.cs.rpi.edu> References: <4dboiv$rlm@netlab.cs.rpi.edu> NNTP-Posting-Host: netlab.cs.rpi.edu X-Original-Date: 15 Jan 1996 22:12:57 GMT