Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!tut.cis.ohio-state.edu!ucbvax!hplabs!hp-pcd!hplsla!jima From: jima@hplsla.HP.COM (Jim Adcock) Newsgroups: comp.lang.c++ Subject: Re: questions about overloaded operators Message-ID: <6590262@hplsla.HP.COM> Date: 26 Sep 89 18:09:47 GMT References: <1346@majestix.ida.liu.se> Organization: HP Lake Stevens, WA Lines: 39 // Sorry, I don't believe you can do what you want to do. You're asking // that the meaning of an expression be determined by context, and C++ [2.0] // won't do that [thank gawd.] C++ will determine the meaning of an expression // regardless of its context, then coerce the resultant type to what you have // specified. Below find what I believe are your reasonable legal options // in C++: // (from your example:) class Pair {}; class Sym { public: Sym(char*); Pair operator/(int); }; class Env { public: Env operator[](Pair); }; void foofoo() { Env e; // option one: Sym foo("foo"); e = e[foo/5]; // option two: e = e[Sym("foo")/5]; // option two_b: e = e[(Sym)"foo"/5]; } // Personally, option one -- requiring you to declare your symbol before using // it -- seems pretty reasonable to me.