Marc Glisse-6 wrote > 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 It doesn't have a base class but does have conversions to char* and const char*. Commenting those out produces the error: error : no match for 'operator[]' in 'foo[0]' for both lines I alleged to be illegal. Mystery solved. Thanks for your help. Regards, John Boncek -- View this message in context: http://gcc.1065356.n5.nabble.com/implicit-operator-member-functions-tp906236p906827.html Sent from the gcc - Help mailing list archive at Nabble.com.