Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!decwrl!pa.dec.com!shlump.nac.dec.com!bolt.enet.dec.com!minow From: minow@bolt.enet.dec.com (Martin Minow) Newsgroups: comp.sys.mac.programmer Subject: Re: C++ for a beginner Message-ID: <20434@shlump.nac.dec.com> Date: 21 Feb 91 22:12:05 GMT Sender: newsdaemon@shlump.nac.dec.com Distribution: comp Organization: Digital Equipment Corporation Lines: 39 In article <1991Feb21.012535.2899@vax5.cit.cornell.edu>, a5uy@vax5.cit.cornell.edu writes... >Here's a first obviously basic question...but a good answer would clear up all >sorts of fog... All the sample progs have a main() that looks like this: > >void main(void) > gApplication = new(CPedestalApp); > ((CPedestalApp*)gApplication)->IPedestalApp(); > gApplication->Run(); > gApplication->Exit(); > > >My question is why does gApplication need to be type cast as a (CPedestalApp*) >in order to send the message IPedestalApp() when, as far as I can tell, it's >type *IS* CPedestalApp* ??? And assuming this type cast is necessary, why is >it *NOT* necessary in order to send messages Run() and Exit() ??? Welcome to methods and prototyping. If you define gApplication as extern CApplication *gApplication; you need to cast it to a (CPedestalApp *) in order to send use a method that is only defined for CPedestalApp's. If, on the other hand, you're sending a CApplication method, you don't need the cast. What I've been doing is to define gApplication to my own application type: gApplication = (MyApplication *) new(MyApplication); gApplication->IMyApplication(); gApplication->Run(); gApplication->Exit(); You should always use "require prototypes" and "check prototypes" on Think C, even if it is painful to cast things at times. Hope this helps. Martin Minow minow@bolt.enet.dec.com