Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!fluke!mce From: mce@tc.fluke.COM (Brian McElhinney) Newsgroups: comp.sys.mac.programmer Subject: Re: Comments on THINK C 4.0 Message-ID: <10485@fluke.COM> Date: 18 Aug 89 23:12:10 GMT References: <10362@fluke.COM> <227700029@uxa.cso.uiuc.edu> Sender: news@tc.fluke.COM Organization: Guild of the Software Defenestrators Lines: 45 In article <227700029@uxa.cso.uiuc.edu> jpd00964@uxa.cso.uiuc.edu writes: >You do not want the new operator to do type checking like that. It should >be extremely easy to allow different objects to be assigned any variable. >For example, assume an object called holder. Subtypes of Holder can be cup, >box, sack, etc. Each of these have identically named routines that act >differently. You should easily be able to have one variable that could be >any of those. No, you must be restricted to the same or sub-classes, not just any class: struct thing { int value; }; struct sub_thing : thing { int thing_value; }; bug() { thing *t; sub_thing *st; t = new(thing); st = new(sub_thing); t = new(sub_thing); /* valid polymorphism */ st = new(thing); /* ERROR: incompatible pointers */ st = (sub_thing *)new(thing); /* run time error: no space reserved */ /* for st->thing_value */ } The compile time error is not caught by THINK C 4.0, leading to the related run time error. THINK C 4.0 is a wonderful product (thanks guys!), that has some slight syntactical similarities to C++. Period. Inheritance isn't the same as C++, because the type checking is different. Brian McElhinney mce@tc.fluke.com PS: the Starter and Pedestal examples have an error in the comments. Where it says "if you want to handle mouse events, put your code here" (paraphrased), it should also mention that you must SetWantsClicks(TRUE) in the initialization method for the pane.