TITLE: operator -> (Newsgroups: comp.std.c++) PROBLEM: rmashlan@r2m.com (Robert Mashlan) I know this might be an old subject, but can someone explain to me why the standard was changed to allow a member operator-> in a template that [snip] may or may not return a pointer to a class type, rather than allowing for non-member overloaded operator -> template function? RESPONSE: clamage@Eng.Sun.COM (Steve Clamage), 3 Jun 96 The general rule requiring operator-> to be a class member function prevents conversions being performed on the left-hand operand. Allowing non-member operator-> could allow surprising conversions instead of error messages. Example: T m; // class T has constructor T(int) // suppose we allowed global operator-> U* operator->(const T&); // class U has member x int n = ...; int i = n->x; // oops, meant m->x In this case, if the global oeprator-> were allowed, the compiler would generate T(n)->x, which is probably not what was intended. Since the global operator-> is not allowed, you get an error. The alternative would be to make some (other) special rule for operator->. We also have a general rule for function templates: The code need not be completely valid except when the function is instantiated. If not for that rule, it would be impossible to write many kinds of templates; you would have to write a dummy function template, and provide specializations for every type of interest. In addition, not every language rule can be checked in a template, particularly anything that depends on a type parameter. Consider: template class MyClass { public: V operator->(); ... } If type V has a member operator->, this function is OK, otherwise it isn't. You can't tell until the class is instantiated whether it might be OK. If you instantiate on some type V that doesn't have an operator->, class MyClass is still OK if you never use operator->. It seemed unnecessary to rule out this possibility. If you attempt to instantiate on an improper class V and use operator->, you get an error. Thus, no special rule is needed for template versions of operator->. The general rules cover all cases.