Scope resolution is something that happens entirely at compile time. The method used in that code results in a direct, inlinable, function call. You can't really beat that.
Your proposal:
- Requires an instance of B to be created somehow
- Requires that a pointer to that instance either be stored in
A
(increasing its size) or in a global (always problematic) - Introduces the need to track that instance's lifetime
In short it has little chance of being as efficient as what you currently have.