It is rumoured that early C++ implementations have had dot operator for namespace access. There is an opinion that the dot is more convenient that the modern double colon operator.
What was the reasoning behind introducing the double colon?
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.
Sign up to join this communityIt is rumoured that early C++ implementations have had dot operator for namespace access. There is an opinion that the dot is more convenient that the modern double colon operator.
What was the reasoning behind introducing the double colon?
As observed by Jules it's a fact that early C++ implementations (CFront pre-1.0) had a dot for scope identification.
A dot was also used in C with Classes (1980). Indeed this is a simple snippet from Classes: An Abstract Data Type Facility for the C Language 1:
class stack {
char s[SIZE]; /* array of characters */
char * min; /* pointer to bottom of stack */
char * top; /* pointer to top of stack */
char * max; /* pointer to top of allocated space */
void new(); /* initialization function (constructor) */
public:
void push(char);
char pop();
};
char stack.pop()
{
if (top <= min) error("stack underflow");
return *(−−top);
}
(the code was an example of how member functions were typically defined "elsewhere")
The ::
was one of the additions to C with Classes introduced to produce C++.
The reason is given by Stroustrup himself:
In C with Classes, a dot was used to express membership of a class as well as expressing selection of a member of a particular object.
This had been the cause of some minor confusion and could also be used to construct ambiguous examples. To alleviate this,
::
was introduced to mean membership of class and.
was retained exclusively for membership of object
(A History of C++: 1979−1991 [2] page 21 - § 3.3.1)
Bjarne Stroustrup: "Classes: An Abstract Data Type Facility for the C Language" - Bell Laboratories Computer Science Technical Report CSTR−84. April 1980.
Bjarne Stroustrup: "A History of C++: 1979−1991" - AT&T Bell Laboratories Murray Hill, New Jersey 07974.
::symbol
to force it to look forsymbol
in the global namespace instead of the current namespace, so that's at least one thing which would look very confusing and probably introduce yet more syntactical ambiguity into the language if the dot operator was used instead.