As far as I understand the -> operator dereferences then accesses the members of a pointer to a class object.
identifier->member is effectively the equivalent to using: (*identifier).member
Consider the following: compiled and tested, functions as expected
#include <iostream>
class A
{
public:
int x{0};
};
class A_Abstraction
{
public:
A *ptrToA;
A_Abstraction() : ptrToA{new A} {};a
A *operator->() { return ptrToA; }
};
int main()
{
A_Abstraction a;
a->x = 10;
std::cout << a->x << '\n';
}
In my basic understanding the A_Abstraction::operator->() would resolve to a A*, which would still require both dereferencing and the use of a member access operator. So wouldn't accessing A::x through A_Abstraction::operator->() require something like this: a->->x
Obviously it doesn't and the code compiles and runs as expected. How does the compiler manage this?