Re: Calling static member function through object instance
On 19 Jan 2004 07:01:14 -0800, bs@research.att .com (Bjarne Stroustrup)
wrote:[color=blue]
>Andy Buchanan <news@globbits. co.uk> wrote in message news:<qusm00drg qgjip58kehcpp24 mvufdig6od@4ax. com>...[/color]
<!--Snipped for brevity-->[color=blue][color=green]
>> It caught me out (shockingly recently), somehow I managed to miss the
>> whole call via instance mechanism for the 8+ years I've used c++, I
>> always used the :: form and I never saw anyone else do otherwise....
>>
>> class BlahBlah
>> {
>> public:
>> BlahBlah& Instance(); // some sort of singleton i/f
>>
>> private:
>> static void Eot( Client* client, int flags, void* uopt )
>> {
>> // Mistaken assumption: overload resolution calls
>> // the non-static member ( due to implicit 'this' )
>> // Actual behaviour: Recursive call & hang!
>> Instance().Eot( client, flags, uopt );
>> }
>> void Eot( Client* client, int flags, void* uopt );
>> };
>>
>> In case you're wondering this was just code to interface
>> to a 3rd party C lib that used callbacks (yuk). Usually I would have
>> had different names for the two Eot() functions, but not this
>> time for some reason.
>>
>> I would have thought the compiler might have determined
>> the Eot call to be amibiguous, but it didn't ( Compiler was a gcc
>> 2.95.x derivitive.). Does a static member function rate higher
>> than an ordinary member function in overload resolution?[/color]
>
>No. That declaration is illegal. From the standard:
>
>"[class.static.mf ct] 9.4.1 Static member functions
>
> There shall not be a static and a nonstatic member function with the
>same name
>and the same parameter types (13.1)."
>
>This has always been the rule. Without that rule, people could get
>into all kinds of nasty problems.[/color]
As indeed I did. I shant be making this mistake again even if the
compiler lets me. Thanks for the pointer.
[color=blue]
>It is always most anoying when a compiler fails to implement a clear
>and simple language rule.[/color]
Alas the compiler in question has allowed a number of other
incorrect constructs. As a further alas, I'm pretty much stuck with
it for the rest of the project (and probably the next). <sigh>
[color=blue]
>
> - Bjarne Stroustrup; http://www.research.att.com/~bs[/color]
On 19 Jan 2004 07:01:14 -0800, bs@research.att .com (Bjarne Stroustrup)
wrote:[color=blue]
>Andy Buchanan <news@globbits. co.uk> wrote in message news:<qusm00drg qgjip58kehcpp24 mvufdig6od@4ax. com>...[/color]
<!--Snipped for brevity-->[color=blue][color=green]
>> It caught me out (shockingly recently), somehow I managed to miss the
>> whole call via instance mechanism for the 8+ years I've used c++, I
>> always used the :: form and I never saw anyone else do otherwise....
>>
>> class BlahBlah
>> {
>> public:
>> BlahBlah& Instance(); // some sort of singleton i/f
>>
>> private:
>> static void Eot( Client* client, int flags, void* uopt )
>> {
>> // Mistaken assumption: overload resolution calls
>> // the non-static member ( due to implicit 'this' )
>> // Actual behaviour: Recursive call & hang!
>> Instance().Eot( client, flags, uopt );
>> }
>> void Eot( Client* client, int flags, void* uopt );
>> };
>>
>> In case you're wondering this was just code to interface
>> to a 3rd party C lib that used callbacks (yuk). Usually I would have
>> had different names for the two Eot() functions, but not this
>> time for some reason.
>>
>> I would have thought the compiler might have determined
>> the Eot call to be amibiguous, but it didn't ( Compiler was a gcc
>> 2.95.x derivitive.). Does a static member function rate higher
>> than an ordinary member function in overload resolution?[/color]
>
>No. That declaration is illegal. From the standard:
>
>"[class.static.mf ct] 9.4.1 Static member functions
>
> There shall not be a static and a nonstatic member function with the
>same name
>and the same parameter types (13.1)."
>
>This has always been the rule. Without that rule, people could get
>into all kinds of nasty problems.[/color]
As indeed I did. I shant be making this mistake again even if the
compiler lets me. Thanks for the pointer.
[color=blue]
>It is always most anoying when a compiler fails to implement a clear
>and simple language rule.[/color]
Alas the compiler in question has allowed a number of other
incorrect constructs. As a further alas, I'm pretty much stuck with
it for the rest of the project (and probably the next). <sigh>
[color=blue]
>
> - Bjarne Stroustrup; http://www.research.att.com/~bs[/color]
Comment