Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!mcsun!sunic!liuida!mikpe From: mikpe@majestix.ida.liu.se (Mikael Pettersson) Newsgroups: comp.lang.c++ Subject: questions about overloaded operators Message-ID: <1346@majestix.ida.liu.se> Date: 20 Sep 89 23:43:21 GMT Organization: CIS Dept, Univ of Linkoping, Sweden Lines: 39 (my statements here are made relative to C++ as implemented by cfront 1.2.1) 1) Why does C++ *require* that at least one of the operands to an overloaded operator *must* be a class object? Does Ver. 2.0 still enforce this restriction? 2) According to the reference manual, conversion constructors ( class X { ... X(type); }; ) are supposed to be used for conversion of function arguments. But apparently they are *not* used to rewrite arguments to operators (implying that operators aren't really "just" functions operator@(...) ), making the follwing attempt fail: class Pair { ... }; class Sym { ... Sym(char*); Pair operator/(int); // yes, I know it looks suspect }; class Env { ... Env operator[](Pair); // update }; foo() { Env e; // empty env e = e["foo"/5]; // here, I'd like Sym::Sym(char*) to // be applied to "foo" automatically. ... // (since Pair operator/(char*,int) // is outlawed) } (if you haven't guessed it, I'm trying to write environment updates in the usual mathematical style e[name/val] rather than e.update(name,val) ) Again, does Ver 2.0 do what I want? /Mike -- Mikael Pettersson, Dept of Comp & Info Sci, University of Linkoping, Sweden email: mpe@ida.liu.se or ..!{mcvax,munnari,uunet}!enea!liuida!mpe