Re: Array using STL
On Jun 14, 8:18 am, Erik Wikstr=F6m <eri...@student.chalmers.se> wrote:
On 14 Juni, 06:00, hlg <h...@ga110n7744.freeserve.co.uk> wrote:
I have a question, which must surely have occurred to many programmers
since STL first appeared, and yet I have found no reference to it
anywhere, suggesting the problem is insoluble.
Read this and the following
FAQs:http://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-=
1...
Nevertheless, here it is:
I wish to create an two-dimensional array of objects. On the one hand,
it is useful to use STL containers for the rows and columns of the
array. On the other, it would be nice to address the elements by the
array element operator [] i.e. myObj obj = myObjArray[x,y];
Sorry, but no can do, operator[] only takes one parameter, use
operator() or [][]-syntax.
Well, his expression only gives it one argument. That's really
where the problem lies, and why you can't overload the way he
would like: myObjArray[x,y] has only a single index, the
expression "x,y", which evaluates x, throws out the result, then
evaluates y, and uses it. Because it is already so defined, you
can't redefine it without breaking code. One might argue that
such code deserves to be broken, but the committee doesn't like
to break code, even if it is bad code.
--
James Kanze (GABI Software, from CAI) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34