Path: utzoo!attcan!uunet!lll-winken!ames!killer!texbell!bellcore!faline!thumper!ulysses!andante!alice!shopiro From: shopiro@alice.UUCP (Jonathan Shopiro) Newsgroups: comp.lang.c++ Subject: Re: A question or two from a Beginner Summary: Using friend operators Message-ID: <8746@alice.UUCP> Date: 13 Jan 89 16:02:53 GMT References: <1001@elmgate.UUCP> Organization: AT&T Bell Laboratories, Murray Hill NJ Lines: 27 Here is a program that should work. struct X { X(char*); ~X(); int dummy; }; int operator==(const X&, const X&); int foo(const X& x) { return "abc" == x; } If operator==() were a member of X instead of a friend, it would not work, since no coercion is done on the object for which a member function is called. Of course this is not very efficient, because an X object is created and destroyed within foo. It would be better to have an additional function int operator==(char*, const X&); -- Jonathan Shopiro AT&T Bell Laboratories, Warren, NJ 07060-0908 research!shopiro (201) 580-4229