Article View: comp.std.c++
Article #1631Re: operator[](int,int)
From: Fergus Henderson
Date: Wed, 02 Aug 1995 13:53
Date: Wed, 02 Aug 1995 13:53
49 lines
2376 bytes
2376 bytes
matt@godzilla.EECS.Berkeley.EDU (Matt Austern) writes:
>fjh@munta.cs.mu.OZ.AU (Fergus Henderson) writes:
>
>> But no standard-conforming code defines `operator[] (int, int)'.
>> If Borland makes `a[ x, y ]' call `operator[] (int, int)' in
>> the case that `a' has an `operator[] (int, int)', it won't
>> affect any standard-conforming code.
>
>I don't think that's true. a[x, y] is a legal C++ expression: it
>is equivalent to a[(x, y)], and, if evaluating x has no side
>effects, it is equivalent to a[y].
You missed the point. `a[x, y]' is a legal C++ expression, but
`operator[] (int, int)' is not a legal C++ declaration. If Borland
were to change the meaning of `a[x, y]' only if the code declares
an `operator[]' with two arguments, then that cannot affect any
standard-conforming code, since no standard-conforming code can
possibly contain such a declaration.
// prog1.cpp - strictly conforming C++ code
struct Foo {
int operator [] (int);
}
void bar(int x, int y) {
Foo foo;
foo[x,y]; // In any standard-conforming compiler, this
// must be equivalent to `foo[y]'.
}
// prog2.cpp - this code is not strictly conforming C++
struct Foo {
int operator [] (int, int);
// The above declaration is "ill-formed".
// The compiler must issue a diagnostic.
}
void bar(int x, int y) {
Foo foo;
foo[x,y]; // Once the above diagnostic has been issued,
// the compiler is free to do anything it likes
// with this code, including calling
// `Foo::operator[](int, int)'.
}
--
Fergus Henderson | Designing grand concepts is fun;
fjh@cs.mu.oz.au | finding nitty little bugs is just work.
http://www.cs.mu.oz.au/~fjh | -- Brooks, in "The Mythical Man-Month".
PGP key fingerprint: 00 D7 A2 27 65 09 B6 AC 8B 3E 0F 01 E7 5D C4 3F
Technical Details
Message-ID:
<9521423.3328@mulga.cs.mu.OZ.AU>Path:
arc1-ca.pugleaf.net!munta.cs.mu.OZ.AU!fjhReferences:
<Pine.SOL.3.90.950706113001.24539A-100000@rphc7> <KANZE.95Jul18183611@slsvhdt.lts.sel.alcatel.de> <9520602.10243@mulga.cs.mu.OZ.AU> <MATT.95Jul24105500@godzilla.EECS.Berkeley.EDU>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++ Path: arc1-ca.pugleaf.net!munta.cs.mu.OZ.AU!fjh From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson) Subject: Re: operator[](int,int) Message-ID: <9521423.3328@mulga.cs.mu.OZ.AU> Sender: news@cs.mu.OZ.AU (CS-Usenet) Organization: Computer Science, University of Melbourne, Australia References: <Pine.SOL.3.90.950706113001.24539A-100000@rphc7> <KANZE.95Jul18183611@slsvhdt.lts.sel.alcatel.de> <9520602.10243@mulga.cs.mu.OZ.AU> <MATT.95Jul24105500@godzilla.EECS.Berkeley.EDU> Date: Wed, 2 Aug 1995 13:53:58 GMT