Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uwm.edu!ogicse!ucsd!ucbvax!hplabs!hpl-opus!hpnmdla!hpmwtd!jeffa From: jeffa@hpmwtd.HP.COM (Jeff Aguilera) Newsgroups: comp.lang.c++ Subject: Re: operator []: ref vs value Message-ID: <1520022@hpmwjaa.HP.COM> Date: 23 Feb 90 18:39:28 GMT References: <5216@brazos.Rice.edu> Organization: HP Microwave Tech. - Santa Rosa, Ca. Lines: 17 > I can't seem to find a way to do precisely what I want; I want a > sparse vector data type. I can declare a float-returning operator [] > that returns 0.0 if the array index corresponds to a row for which no > nonzero is stored. I can declare a reference-to-float-returning > operator[] that creates a new entry in my linked list of nonzero > values when the row has no corresponding nonzero stored. > Unfortunately, I want one behavior when the pseudo-array access occurs > as an rvalue and another when it appears as an lvalue. Can I get what > I want? Here's one way, but it's not so pretty: float spare_matrix::operator[](int); //read-only access float& spare_matrix::operator()(int); //possible write-to access ----- jeffa