Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!apple!usc!cs.utexas.edu!yale!mintaka!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!edcastle!cs.ed.ac.uk!cs.edinburgh.ac.uk!nick From: nick@cs.edinburgh.ac.uk (Nick Rothwell) Newsgroups: comp.sys.mac.programmer Subject: Re: Casting in Think C Keywords: Casts ThinkC Message-ID: <3028@skye.cs.ed.ac.uk> Date: 5 Dec 90 12:30:46 GMT References: <6167@munnari.oz.au> Sender: nnews@cs.ed.ac.uk Reply-To: nick@lfcs.ed.ac.uk Organization: Wavetables 'R' Us Lines: 35 In article <6167@munnari.oz.au>, caw@munnari.oz.au (Chris Wright) writes: > Why do you have to cast gApplication in ThinkC e.g.: > extern CApplication *gApplication; > > void main() > > { > gApplication = new(CEditApp); > ((CEditApp *) gApplication)->IEditApp(); > gApplication->Run(); > gApplication->Exit(); > } > > if you remove the cast and try gApplication -> iEditApp(), the compiler > complains. As it should. I'm not sure what the argument to new() actually is/does, but my guess is that it just provides a size (a la "sizeof") to determine how much store to claim. gApplication is still a CApplication, and hence doesn't have an IEditApp() method unless you cast it. > new is meant to "automatically assign a class to the newly created object" Now, I've never understood what this kind of thing means, ditto for Bless() and all the rest. Presumably it does something automagical to the method dispatcher. Anybody care to comment what "the class of an object" actually means (as opposed to the static type of the object pointer)? -- Nick Rothwell, Laboratory for Foundations of Computer Science, Edinburgh. nick@lfcs.ed.ac.uk !mcsun!ukc!lfcs!nick ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ "You ain't seen nothing yet. I can take this floor out too, no trouble."