TITLE: Why is operator = required to be a member? PROBLEM: bruce@jise.isl.melco.co.jp (Bruce Hahne) So my question is, would there be anything inherently dangerous or problematic about C++ if it allowed something like this? : class myclass { // stuff here }; int operator=(int left, myclass& right) { // Do whatever I want here } RESPONSE: clamage@taumet.Eng.Sun.COM (Steve Clamage), 13 Jun 94 [ meaning operator= allowed to be a non-member function ] There are two reasons why operator= is required to be a member function. 1. Assignment is predefined for all types, including all user types. If op= is not required to be a class member, you could get different semantics for assignment depending on whether the prototype was in scope. This is a silly error with dangerous consequences which would be very difficult to find. This situation is not a problem for other operators which are not predefined for class types. If you omit the prototype, code using the function will not compile. 2. When an overloaded op is a member function, you do not get type conversion on the first argument. Indeed, you do not want type conversion on the first argument for op=. You could get a situation where no op= matched on the first argument, but you could make a new anonymous temp from the object on the left, and assign to it. It is very unlikely that you want that to happen. In the cases where you do want it, you can write the appropriate casts or create explict temps. This is the reasoning for those other ops which also must be member functions. In most cases, the left argument would be a non-const reference, and you wouldn't get type conversion anyway. In the example above you forgot to make the left arg a reference, which just helps illustrate my point!