Path: utzoo!attcan!uunet!wuarchive!usc!bbn.com!nic!chaos.cs.brandeis.edu!chaos!phils From: phils@chaos.cs.brandeis.edu (Phil Shapiro) Newsgroups: comp.sys.mac.programmer Subject: Re: Casts and Think C - Thanks and one little ?... Message-ID: Date: 10 Dec 90 15:14:35 GMT References: <6225@munnari.oz.au> Sender: phils@chaos.cs.brandeis.edu (Phil Shapiro) Organization: Symantec Corp. Lines: 31 In-Reply-To: caw@munnari.oz.au's message of 8 Dec 90 09:11:02 GMT In article <6225@munnari.oz.au> caw@munnari.oz.au (Chris Wright) writes: If gApplication is still a CApplication at compile time (which makes sense), then I can see the need for the cast in ((CEditApp *) gApplication) -> IEditApp; and I can see that gApplication -> Run(); doesn't need a cast, 'cos CApplication has a Run() method. But why does the correct Run() method get executed at run time.? That is, how does the compiler set it up so that CEditApp's Run() method is executed, instead of the (default) CApplication's Run() method? The __msg() method dispatcher (in oops.c) examines the object's Class ID at *run time*. That's why every method call (except for monomorphic methods) is made through the method dispatcher. At compile time, all the compiler can assume is that there's an object (of some type) that's calling a method, which has a Message ID. The compiler needs to know the class from which this method is called, so it can generate the correct Message ID. -phil -- Phil Shapiro Technical Support Analyst Language Products Group Symantec Corporation Internet: phils@chaos.cs.brandeis.edu -- Phil Shapiro Technical Support Analyst Language Products Group Symantec Corporation