This is the mail archive of the gcc-bugs@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: g++ operator() inheritance problem


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


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