Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!wuarchive!zaphod.mps.ohio-state.edu!think.com!hsdndev!husc6!endor!siegel From: siegel@endor.uucp (Rich Siegel) Newsgroups: comp.sys.mac.programmer Subject: Re: C/C++ difference? Message-ID: <5720@husc6.harvard.edu> Date: 13 Feb 91 16:22:19 GMT References: <49114@apple.Apple.COM> Sender: news@husc6.harvard.edu Reply-To: siegel@endor.UUCP (Rich Siegel) Organization: Symantec Language Products Group Lines: 62 In article <49114@apple.Apple.COM> marc@Apple.COM (Mark Dawson) writes: >>1) my think C manual says it is upwards compatable with c++, meaning >> think C is lacking something in c++. what exactly is it lacking? >C++ supports > o data abstraction the data needed by that code is local to that > code; if you want access to that data, you have to ask > the code ("object") to get it for you) > o inheritance you can derive a new user-defined type from an old one > and make changes only where you need them--in theory this > makes for easier code reuse) > o polymorphism the actual creating of a new user-defined type that can > inherit (or not) properties of the old type, plus add > something. For example, you could have a type "oval" > that draws an oval. Using polymorphism, you could derive > a sub-type called "circle" that uses (inherits) all of > "oval"'s drawing routines, but defines that the x & y > axises (sp?) are the same. Actually, THINK C does support all three of these things; you can write your own methods to abstract the instance variables of an object. What THINK C does not provide is compiler-enforced abstraction through the use of keywords such as "private", "protected", and "friend". THINK C supports the Object Pascal model of inheritance, that is, a class can inherit its characteristics from only one superclass. C++ supports multiple inheritance, in which a class can derive its characteristics from more than one superclass. In your description, you've confused inheritance and polymorphism; in fact, both of the things you describe (inheriting characteristics from an ancester class and overriding the inherited behavior) are features of the inheritance model. Polymorphism means that you can have to disjoint types of object which both have a message of the same name, but the name means different things for each class. Consider: TYPE Shape = object procedure Draw; end; Square = object (Shape) sideLength : Integer; procedure Draw; Override; end; Oval = object(Shape) majorAxis : Integer; minorAxis : Integer; procedure Draw; Override; end; The "Draw" message has different meaning to an Oval object than it has to the "Square" object. R. Rich Siegel Symantec Languages Group Internet: siegel@endor.harvard.edu "I was just trying to be subtle. That's my job, isn't it?"