I was reading the book C++ Primer by Stanley B. Lippman and in the section of Variables and Basic Types I saw the scope operator ::
.
I had already read a little about the operator overload and I think it could be very useful in special cases, but when I searched in the internet I found out that I simply cannot overload the ::
operator.
In this post I found that the .
operator can be overload. However, this can lead to questions about whether an operation is meant for the object overloading .
or an object referred to by .
.
Thus, I think that maybe there is a way to overload the ::
.
But if it can't, can anyone explain me why?
An example of my idea for the :: operator:
#include <iostream>
/*
*For example:
*I wanna increase 1 unit every time
*I call the global variable r doing ::r
*insede of the main function
*/
int r = 42;
int main()
{
int r = 0;
std::cout << ::r << " " << r << std::endl; //It would print 43 0 after the operator overload
return 0;
}