TITLE: return type of operator -> (Newsgroups: comp.lang.c++.moderated, 5 Oct 98) HELCK: C Helck |>> Why does the following produce an error? (Solaris & MS compilers) |>> |>> class X { int* p; int* operator->() {return p;} }; OLIVA: Alexandre Oliva |> Because the compilers are wrong. operator-> needs not return a |> pointer to a class type. In fact, it does not have to return a |> pointer. However, in order to be able to write: |> |> x->foo; |> |> given that x is an instance of X, then operator-> must return a |> pointer to a class type that has a member named foo, that is not a |> member function. |> |> If operator-> returns anything other than a pointer to class type, |> then the only way you can use it is by writing: |> |> x.operator->(); KANZE: kanze@gabi-soft.fr (J. Kanze) Note that this is a recent clarification. Some compilers may still implement the earlier rule, in which operator-> was required to return either a pointer to a class or a union, or a class type or a reference to a class type which overloaded operator->.