Re: Why :: ? Why not : ? Why not . ? <- less clutter ?!?
* Skybuck Flying:
Hello,
Why does C++ use :: for members/methods why not just : ?
For example:
long Test::TimesOne() const { return mVal; }
Alternative:
long Test:TimesOne() const { return mVal; }
Why use : at all ? Why not stick to . ?
long Test.TimesOne() const { return mVal; }
^^^ Less clutter ^^^
This choice is probably covered in Bjarne Stroustrup's "Design and
Evolution"-book.
But the short of it is that
.
is performed at run time, whereas
::
is evaluated (if that word can be said to apply) only at compile time.
It was found to be useful to distinguish these cases syntactically, so
that the effect of the code is reflected directly in the syntax.
Regarding ":" instead of "::", that would introduce additional possible
ambiguity for the parser, e.g. an expression such as
(condition?Foo:Bar:other)
The problem here being that ":" is already an operator that is evaluated
at run time, in a context where also the "::" can appear.
Also, ":" as a scope resolution operator would interfere with ":"
denoting inheritance, like in
class Humpty:Dumpty:Alice {};
Is this a class Humpty inheriting from Dumpty:Alice, or a class
Humpty:Dumpty inheriting from Alice, or a class Humpty:Dumpty:Alice?
However, none of the above would be a problem with ".", and Java and C#
manage just fine using ".". And as I recall, but I'm not sure, "." was
used this way in early pre-standard C++. However, already by 1987 the
"::" as scope resolution operator had been adopted, so presumably, if
"." was ever used, it turned out to have some problems in C++.
Cheers, & hth.,
- Af
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?