Message-Id: <199708191127.UAA28352@sadecs.nexus.edu.au> From: "Tom Cook" To: "DJGPP mailing list." Subject: Re: C++ overloaded operators and operator preceedence Date: Mon, 18 Aug 1997 19:30:23 +0930 MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Precedence: bulk Jeff Weeks wrote: > Alright, does anybody know if operator preceedence (or, order of > operations) is preserved when you overload an operator in C++? From the MSVC 1.00 docs: The operator keyword declares a function specifying what operator-symbol means when applied to instances of a class. This gives the operator more than one meaning, or "overloads" it . The compiler distinguishes between the different meanings of an operator by examining the types of its operands. Rules of Operator Overloading You can overload the following operators: + - * / % ^ ! = < > += -= ^= &= |= << >> <<= <= >= && || ++ -- ( ) [ ] new delete & | ~ *= /= %= >>= == != , -> ->* If an operator can be used as either a unary or a binary operator, you can overload each use separately. You can overload an operator using either a nonstatic member function or a global function that's a friend of a class. A global function must have at least one parameter that is of class type or a reference to class type. If a unary operator is overloaded using a member function, it takes no arguments. If it is overloaded using a global function, it takes one argument. If a binary operator is overloaded using a member function, it takes one argument. If it is overloaded using a global function, it takes two arguments. Restrictions on Operator Overloading You cannot define new operators, such as **. You cannot change the precedence or grouping of an operator, nor can you change the numbers of operands it accepts. You cannot redefine the meaning of an operator when applied to built-in data types. Overloaded operators cannot take default arguments. You cannot overload any preprocessor symbol, nor can you overload the following operators: . .* :: ?: :> The assignment operator has some additional restrictions. It can be overloaded only as a nonstatic member function, not as a friend function. It is the only operator that cannot be inherited; a derived class cannot use a base class's assignment operator. Be warned, VC1.0 is OLD! This may have changed, but as far as I know it's still right. Someone please correct me if this is wrong. Hope this helps. Tom Cook