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]