This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: g++ operator() inheritance problem
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: Bill Beckett <wb at typhoon dot graysoft dot com>
- Cc: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 24 Jun 2002 18:12:16 +0100
- Subject: Re: g++ operator() inheritance problem
- Organization: Codesourcery LLC
- References: <200206240243.g5O2hPe21328@typhoon.graysoft.com>
Bill Beckett wrote:
> I believe that you will find that the following pair of
> programs demonstrate a curious problem --
no, you misunderstand c++ :-)
> /* However, when a different function call operator, */
> /* operator()(), is added to B, the operator()(int) defined */
> /* in A appears to no longer be inherited. */
>
> struct A
> {
> void operator ()(int i)
> {
> cout << "A.operator(), i = " << i << endl;
> }
> };
>
> struct B : A
> {
> void operator()()
> {
> cout << "B.operator()" << endl;
> }
> };
C++ name lookup will look for operator() in B, and then iff it doesn't
find a set of overloaded functions of that name, will it look in B's
bases. To do what you want you need to add
using A::operator () (int);
to B's definition.
You'll find the same problem if you use functions called 'Foo' or
whatever, rather than the slightly more confusing 'operator()'
nathan
--
Dr Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org