Hi, now my curiosity is stuck on arrow operator. Is there a way to overload an arrow operator from a pointer object? If none, what's the reason that this isn't allowed? or is there a correct/better approach?
class B
{
public:
void foo() {}
};
class A
{
public:
B* b;
B* operator->()
{
return b;
}
};
int main()
{
A a;
a->foo(); // Works.
A* pa = new A();
(pa->operator->())->foo(); // Works.
pa->foo(); // Doesn't work as it refers directly to A's foo() which doesn't exist instead of triggering operator->() first.
return 0;
}
Cheers. ?