Path: utzoo!utgpu!water!watmath!clyde!att!rutgers!mit-eddie!uw-beaver!cornell!rochester!pt.cs.cmu.edu!f.gp.cs.cmu.edu!dld From: dld@f.gp.cs.cmu.edu (David Detlefs) Newsgroups: comp.lang.c++ Subject: A C++ revelation/question... Message-ID: <2767@pt.cs.cmu.edu> Date: 22 Aug 88 18:39:31 GMT Sender: netnews@pt.cs.cmu.edu Organization: Carnegie-Mellon University, CS/RI Lines: 41 I recently had a misconception that I had held about C++ corrected. I am writing here to 1) save other people the embarassment of insisting that C++ is X, when it is actually Y, as I did, and 2) get some clarification on the example in The (Stroustrup) Book that caused me to think Y was the case. C++ is of course an object-oriented language. However, some OOL literature makes a subtle distinction between languages that are (truly) "object-based" and those that are "type-based." The distinction is that in an object-based language, a member function (method) of a class only has access to the private members of the object it is invoked on. If we neglect some hacks used for debugging, Smalltalk is an example of a language that is object-oriented in this way. "Type-based" languages allow a member function of a class access to the private part of any object of that class (type) that it has access to. CLU and OWL are examples of languages that are type-based in this sense. Well, my reading of The Book gave me the impression that C++ fell on the object-based side of this distinction. Well, lo and behold, I'm wrong -- it's type based. My error is obvious in hindsight -- the "tiny" example on page 175 can be explained in no other way. However, I'm still a little confused. On page 174, in the "complex" example, and again on page 178 in the "matrix" example, "operator+" is declared as a friend instead of as a member function. This is what originally led me to believe that C++ was object-based (having missed the importance of the "tiny" example) -- I thought that these operator+'s were friends so that they could have access to the private parts of the second argument and the return matrix or complex. Well, this works just as well as a non-friend member function (I just compiled it.) My question is, then, why were these friends? Does it have something to do with operator overloading name resolution? By the way, don't get me wrong -- I think the type-base approach is far superior. -- Dave Detlefs Any correlation between my employer's opinion Carnegie-Mellon CS and my own is statistical rather than causal, dld@cs.cmu.edu except in those cases where I have helped to form my employer's opinion. (Null disclaimer.)