Why .* operator can not be overloaded in c++?
c++, operator-overloading
Solution
From the Horse's mouth:
Operator `.` (dot) could in principle be overloaded using the same technique as used for ->. However, doing so can lead to questions about whether an operation is meant for the object overloading `.` or an object referred to by `.` For example:
class Y {
public:
void f();
// ...
};
class X { // assume that you can overload .
Y* p;
Y& operator.() { return *p; }
void f();
// ...
};
void g(X& x)
{
x.f(); // X::f or Y::f or error?
}
This problem can be solved in several ways. At the time of standardization, it was not obvious which way would be best.
AFAIU the same reasoning applies for `.*`
Problem
I found out few of the post here discussing about operator overloading and operators which can not be overloaded in c++ like `.` `::` `.*` `sizeof` etc . But I could not find out exact details or reason about why should `.*` be avoided ? Few of you might vote it as duplicate but I would be more than happy if I get details on those link about what I want :)