Why is `::` called the 'scope resolution operator' when it doesn't act like an operator?

  • A+
Category:Languages

I can't think of a case when using :: to specify a scope would result in any code being generated. Every other operator I can think of actually (at least conceptually) generates code, it 'does something'.

So why is :: called the 'scope resolution operator' when it in no way behaves like an operator. It seems more to me like part of a name, a bit of lexical fluff like ... or the < and > surrounding a template parameter list, or even ;. Nobody calls ; the 'expression termination operator'.

Is there a specific reason it's called that (a quote from the standard on how it somehow behaves like an operator would be in order here)? Or is the name just historical baggage?

 


But it is an operator, as much as say the member selection operator .:

#include <iostream> int n; int main() {     int n = 1;     std::cout << ::n << " " << n; } 

and

#include <iostream> struct N {     int n = 1;     operator int() const {return 0;} }; int main() {     N n;     std::cout << n << " " << n.n; } 

The output is the same in both cases.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: