a5uy@vax5.cit.cornell.edu (02/21/91)
I've done a lot of programming on other platforms but never on the Mac. I need to put a fairly simple graphics application together in a hurry and find myself trying to learn C++ in the process so I can use the class library included with THINK C. Suggestions on good reference/tutorial books would be greatly appreciated! 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() ??? Thanks for any and all info!!! Since this is probably too basic for this group, feel free to answer via E-mail! Jan Speth The strong force is mediated by gluons, A5UY@VAX5.CIT.CORNELL.EDU not to be confused with cyano-acrylate ester, A5UY@CRNLVAX5 which is Krazy Glue.
minow@bolt.enet.dec.com (Martin Minow) (02/22/91)
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