Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site alice.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!alice!bs From: bs@alice.UucP (Bjarne Stroustrup) Newsgroups: net.lang.c++ Subject: the C++ scope operator Message-ID: <5053@alice.uUCp> Date: Fri, 28-Feb-86 13:27:40 EST Article-I.D.: alice.5053 Posted: Fri Feb 28 13:27:40 1986 Date-Received: Sat, 1-Mar-86 17:23:02 EST Organization: Bell Labs, Murray Hill Lines: 41 > Subject: the C++ scope operator > Path: ..!think!rose (John Rose @ Thinking Machines, Cambridge, MA) > (Thanks for the feedback.) > > What are some plausible uses of the scope operator "::"? > Here are a few: > (1) Definitions of members outside the main declaration. > (2) Invoking an inherited member function. > (3) Random violations of class abstraction. > > Amusingly, the same "::" syntax is used in Common Lisp for something > corresponding to Number 3. That similarity is puly accidental. > Perhaps because of that reinforcement, > something in me winces when I see the scope operator used: > "Get ready for trouble, because someone's poking their nose > where they shouldn't". The scope operator is a danger sign > to readers of code, much like the cast is. In Common Lisp, that is. > I think Number 1 doesn't set off those alarms because it occurs > in a very specialized context: In a (usually unique) file of > definitions, in top-level declarators. > > But (and this is my main point) Number 2, while syntactically > indistinguishable from the alarming Number 3, is a perfectly > safe, reasonable, and common operation. Thanks, but note that (3) is not C++: ``::'' simply allows you to state the full name of something. If that something happens to be private it is still private even if you use ``::''. - Bjarne Stroustrup (AT&T Bell Labs, Murray Hill) P.S. and yes, I know there are problems with expressing a reference to a base class using the ``class_name::member_name'' notation (as opposed to a ``relative address'' notation, for example ``base::member_name''), but it does have one advantage: it scales to handle multiple inheritance.