From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7251fa99aab97e06 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1993-03-16 02:09:12 PST Newsgroups: comp.lang.ada Path: sparky!uunet!pipex!sunic!news.lth.se!dag From: dag@control.lth.se (Dag Bruck) Subject: Re: Encapsulation in Ada vs. C++ (Was Re: Ichibah [sic] ...) Message-ID: <1993Mar16.095150.9735@lth.se> Summary: Of course you can break encapsulation. Sender: news@lth.se Organization: Department of Automatic Control, Lund, Sweden References: <1993Mar7.191557.5547@evb.com> <1993Mar8.153639.3603@inmet.camb.inmet.com> <1993Mar9.181231.27197@intellistor.com> <1993Mar11.082214@lglsun.epfl.ch> <1993Mar16.063423.4679@lth.se> <1993Mar16.083809@lglsun.epfl.ch> Date: Tue, 16 Mar 1993 09:51:50 GMT Date: 1993-03-16T09:51:50+00:00 List-Id: In magnus@lglsun.epfl.ch (Magnus Kempe) writes: >dag@control.lth.se (Dag Bruck) writes: >: A [C++] class grants friendship to other functions or classes, which means >: that the author of a class controls who gets access to the private >: members of the class. You cannot grant yourself access to any random >: class. > >If your class Foo grants "friendship" to a function/class Bar, _anyone_ >can write such a function/class and, having granted itself "friendliness", >will have access to the internals of Foo. If we assume that the author of a class also writes the classes/functions he/she grants friendship, the "one definition rule" prohibits you from writing a second function or class with the same name. The alternative, that the author grants friendship without actually writing the friend classes/functions, seems highly unlikely. If you manipulate library files, for example, replace standard functions with functions you have written yourself, then you can of course get access to anything. You may also patch the symboltable or the objectcode itself. However, I doubt that Ada is safer in this respect. There is a much simpler way to break encapsulation (and I'm sure Magnus Kempe wants to hear it): write a your own class with the same contents and copy the bits from the protected object to a look-alike object with standard C function "memcpy". I doubt that "unsafe" features of this nature is of any real interest. Can anyone give a plausible example? -- Dag