TITLE: Is global operator & allowable? RESPONSE: jamshid (Jamshid Afshar), 24 Jun 94 The following code is legal and allowed by our compilers: ---- class Proxy { public: class Foo* f; }; class Foo {}; // nonmember function const Foo* operator&(const Proxy& x) { return x.f; } ---- D&E 3.6.2 has a good discussion of why operator=() must be a member on p82: "The original idea was to allow every operator to be either a member or a global function. [...] The problem is that unless operator=() is a member, a program can have two different interpretations of = dependent on the location of in the source code [...example...]. in the original design of C++, I restricted operators [], (), and -> to be members. It seemed a harmless restriction ... However, it is probably a case of unnecessary nannyism". [...] [ Jam thought that the table below would be a good addition to this. (from ARM 12.3c p306) -adc ] 12.3c Summary of Member, Friend, and Special Functions -------------------------------------------------------------------------- can be can have member generated inher virt ret typ or friend by default -------------------------------------------------------------------------- constructor no no no member yes destructor no yes no member yes conversion yes yes no member no = no yes yes member yes () yes yes yes member no [] yes yes yes member no -> yes yes yes member no op= yes yes yes either no new yes no void* static member no delete yes no void static member no other operator yes yes yes either no other member yes yes yes member no friend no no yes friend no