This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: Function overloading
- From: "Atwood, Robert C" <r dot atwood at imperial dot ac dot uk>
- To: "Wesley Smith" <wesley dot hoke at gmail dot com>, <gcc-help at gcc dot gnu dot org>
- Date: Wed, 21 Mar 2007 12:21:25 -0000
- Subject: RE: Function overloading
That does not make sense to me, in the original example the function is
not what I would call 'overloaded', as I understand a function in a
derived class is not in the same scope as a function in a base class, so
a function with the same name _hides_ the function from the base class
rather than overloading it, resulting in the behaviour observed by the
original poster.
I don't see how the prohibition of overloading a static function with
the same parameter types applies to hiding a function with _different_
parameter types?
Happy to be corrected if I'm wrong,
Robert
> -----Original Message-----
> From: gcc-help-owner@gcc.gnu.org
> [mailto:gcc-help-owner@gcc.gnu.org] On Behalf Of Wesley Smith
> Sent: 21 March 2007 07:26
> To: gcc-help@gcc.gnu.org
> Subject: Re: Function overloading
>
> Wow that really clarifies things. Is there an URL for this
> documentation?
> Many thanks,
> wes
>
> On 3/21/07, Vadim Doroginin <archimed7592@gmail.com> wrote:
> > On 3/21/07, Wesley Smith <wesley.hoke@gmail.com> wrote:
> > > I have a question about function overloading. I'm getting alot of
> > > errors when I do the following
> > >
> > > class A
> > > {
> > > void draw();
> > > };
> > >
> > >
> > > class B : public A
> > > {
> > > static int draw(lua_State *L);
> > > static B * get(lua_State *L, int i);
> > > }
> > >
> > > //bad
> > > int B :: draw(lua_State *L)
> > > {
> > > B *b = get(L, 1);
> > > b->draw() //<--- produces error because it things
> I'm calling
> > > the static B function
> > > }
> > >
> > >
> > > //good
> > > int B :: draw(lua_State *L)
> > > {
> > > B *b = get(L, 1);
> > > b->A::draw() //<--- no errors
> > > }
> > >
> > >
> > >
> > > Shouldn't the compiler understand that I'm actually calling the
> > > superclass' draw method, especially since the class' draw
> method is
> > > static and I'm calling it as an instance method?
> > >
> > > thanks,
> > > wes
> > >
> >
> > No.
> > IS 13.1 says:
> > Certain function declarations cannot be overloaded:
> > - Function declarations that differ only in the return type
> cannot be
> > overloaded.
> > - Member function declarations with the same name and the same
> > parameter types cannot be overloaded if any of them is a
> static member
> > function declaration (9.4). Likewise, member function template
> > declarations with the same name, the same parameter types, and the
> > same template parameter lists cannot be overloaded if any
> of them is a
> > static member function template declaration. The types of
> the implicit
> > object parameters constructed for the member functions for
> the purpose
> > of overload resolution (13.3.1) are not considered when comparing
> > parameter types for enforcement of this rule. In contrast,
> if there is
> > no static member function declaration among a set of member function
> > declarations with the same name and the same parameter types, then
> > these member function declarations can be overloaded if
> they differ in
> > the type of their implicit object parameter. [Example: the following
> > illustrates this distinction:
> > class X {
> > static void f();
> > void f(); // ill-formed
> > void f() const; // ill-formed
> > void f() const volatile; // ill-formed
> > void g();
> > void g() const; // OK: no static g
> > void g() const volatile; // OK: no static g
> > };
> > -end example]
> >
>