From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10155 invoked by alias); 21 Mar 2007 12:21:50 -0000 Received: (qmail 10145 invoked by uid 22791); 21 Mar 2007 12:21:49 -0000 X-Spam-Check-By: sourceware.org Received: from mr3.cc.ic.ac.uk (HELO mr3.cc.ic.ac.uk) (155.198.5.113) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 21 Mar 2007 12:21:42 +0000 Received: from icexp1.cc.ic.ac.uk ([155.198.3.41] helo=icex.imperial.ac.uk) by mr3.cc.ic.ac.uk with smtp (Exim 4.63) (envelope-from ) id 1HTzox-0005hI-8E; Wed, 21 Mar 2007 12:21:39 +0000 Received: from icex1.ic.ac.uk ([155.198.3.1]) by icex.imperial.ac.uk with Microsoft SMTPSVC(6.0.3790.1830); Wed, 21 Mar 2007 12:21:29 +0000 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: RE: Function overloading Date: Wed, 21 Mar 2007 12:26:00 -0000 Message-ID: <2CB39EAF0E0EFF498ADEDA636B8C999F04C39621@icex1.ic.ac.uk> In-Reply-To: <1079b050703210026x25d2ebeehb09fd4c9c047c806@mail.gmail.com> From: "Atwood, Robert C" To: "Wesley Smith" , X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2007-03/txt/msg00278.txt.bz2 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. =20 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?=20 Happy to be corrected if I'm wrong, Robert > -----Original Message----- > From: gcc-help-owner@gcc.gnu.org=20 > [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 >=20 > Wow that really clarifies things. Is there an URL for this=20 > documentation? > Many thanks, > wes >=20 > On 3/21/07, Vadim Doroginin wrote: > > On 3/21/07, Wesley Smith 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 =3D get(L, 1); > > > b->draw() //<--- produces error because it things=20 > I'm calling > > > the static B function > > > } > > > > > > > > > //good > > > int B :: draw(lua_State *L) > > > { > > > B *b =3D 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=20 > 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=20 > cannot be > > overloaded. > > - Member function declarations with the same name and the same > > parameter types cannot be overloaded if any of them is a=20 > 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=20 > of them is a > > static member function template declaration. The types of=20 > the implicit > > object parameters constructed for the member functions for=20 > the purpose > > of overload resolution (13.3.1) are not considered when comparing > > parameter types for enforcement of this rule. In contrast,=20 > 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=20 > 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] > > >=20