TITLE: Overloading operator * and others PROBLEM: xichen@birkhoff.harvard.edu (Xi Chen), 20 Apr 93 Can I overload operator '->'? If i can, what is the syntax? Thanks in advance! RESPONSE: jimad@microsoft.com (Jim Adcock), 21 Apr 93 Microsoft Corporation Yes you can overload this operator -- but it may not do what you expect it to do. Remember, '->' is a "class member access operator" not a dispatch operator. See ARM page 337. Thus, '->' is spec'ed as a *unary* not a *binary* operator. class Y { public: int m(); }; class X { Y* py; public: Y* operator->() { return py; } }; main() { X* px; .... px->m(); // same as px->py->m(); } If you want to overload a *binary* operator, you'd have to use '->*' instead: (px->*pmf)(); -- which is ugly enough syntax that most people aren't very tempted to overload it. Also, while C++ allows you to overload '->' and '->*', unfortunately it does not allow you to equivalently overload '.' and '.*'. Thus C++ supports the notion of "smart pointer classes" but unfortunately disallows the symmetrically required "smart reference classes". IE if a user dereferences an object of a "smart pointer class" the result should be an object of a "smart reference class" -- yet C++ does not support writing such a class.