Thread View: net.lang.c++
1 messages
1 total messages
Started by Bjarne Stroustrup
Fri, 28 Feb 1986 18:27
the C++ scope operator
Author: Bjarne Stroustrup
Date: Fri, 28 Feb 1986 18:27
Date: Fri, 28 Feb 1986 18:27
41 lines
2212 bytes
2212 bytes
> 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.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads