This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: implicit operator[] member functions?


On Fri, 18 Jan 2013, John Boncek wrote:

Using gcc 4.4.3 (Ubuntu 4.4.3-4ubuntu5), I have a C++ class CFoo that doesn't
define an operator[] member function and has no base classes.  But use of []
is allowed by the compiler, like this:

CFoo  foo;
CFoo  test;
test = foo[0];
foo[0] = 0;

Both assignment statements seem illegal to me but cause no errors.  I cannot
post the class itself because it contains sensitive information.

If you reduce the example, it will both lose the sensitive information and become easier to understand for everyone, clearly worth it!


Can anyone explain what's going on here? Specifically, is this a compiler bug, or are implicit operator[] member functions sometimes generated by the compiler and under what rules? Thanks for your attention.

Is your class convertible to anything? Does it have a base class?


--
Marc Glisse


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]