* Function overloading @ 2007-03-21 7:26 Wesley Smith [not found] ` <32380a010703210019o70bfe7d4ge45ced3c3838f412@mail.gmail.com> 0 siblings, 1 reply; 4+ messages in thread From: Wesley Smith @ 2007-03-21 7:26 UTC (permalink / raw) To: gcc-help 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <32380a010703210019o70bfe7d4ge45ced3c3838f412@mail.gmail.com>]
* Re: Function overloading [not found] ` <32380a010703210019o70bfe7d4ge45ced3c3838f412@mail.gmail.com> @ 2007-03-21 10:38 ` Wesley Smith 2007-03-21 11:57 ` Andrew Haley 2007-03-21 12:26 ` Atwood, Robert C 0 siblings, 2 replies; 4+ messages in thread From: Wesley Smith @ 2007-03-21 10:38 UTC (permalink / raw) To: gcc-help 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] > ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Function overloading 2007-03-21 10:38 ` Wesley Smith @ 2007-03-21 11:57 ` Andrew Haley 2007-03-21 12:26 ` Atwood, Robert C 1 sibling, 0 replies; 4+ messages in thread From: Andrew Haley @ 2007-03-21 11:57 UTC (permalink / raw) To: Wesley Smith; +Cc: gcc-help Wesley Smith writes: > Wow that really clarifies things. Is there an URL for this > documentation? http://www.open-std.org/jtc1/sc22/wg21/ Andrew. ^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: Function overloading 2007-03-21 10:38 ` Wesley Smith 2007-03-21 11:57 ` Andrew Haley @ 2007-03-21 12:26 ` Atwood, Robert C 1 sibling, 0 replies; 4+ messages in thread From: Atwood, Robert C @ 2007-03-21 12:26 UTC (permalink / raw) To: Wesley Smith, gcc-help 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] > > > ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-03-21 12:21 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2007-03-21 7:26 Function overloading Wesley Smith [not found] ` <32380a010703210019o70bfe7d4ge45ced3c3838f412@mail.gmail.com> 2007-03-21 10:38 ` Wesley Smith 2007-03-21 11:57 ` Andrew Haley 2007-03-21 12:26 ` Atwood, Robert C
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).