Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   pointers to member functions - can they point to operators ? (http://www.velocityreviews.com/forums/t955020-pointers-to-member-functions-can-they-point-to-operators.html)

Stephen Howe 12-01-2012 11:03 PM

pointers to member functions - can they point to operators ?
 
Hi

Is is possible to set a pointers to member function to point to an operator - implemented as a class member obviously. I suppose this hinges on whether the address operator can be applied to a class member operator.

It is unusual, I have not seen it done but that does not mean it is impossible.

Thanks

Stephen Howe

W Karas 12-02-2012 01:11 AM

Re: pointers to member functions - can they point to operators ?
 
On Saturday, December 1, 2012 6:03:42 PM UTC-5, Stephen Howe wrote:
> Hi
>
>
>
> Is is possible to set a pointers to member function to point to an operator - implemented as a class member obviously. I suppose this hinges on whether the address operator can be applied to a class member operator.
>
>
>
> It is unusual, I have not seen it done but that does not mean it is impossible.
>
>
>
> Thanks
>
>
>
> Stephen Howe


g++ compiles this code:


class A { };

A operator + (A a1, A a2);

typedef A (*Fr)(A, A);
Fr foo(void) { return(operator +); }

Richard Damon 12-02-2012 01:33 AM

Re: pointers to member functions - can they point to operators ?
 
On 12/1/12 6:03 PM, Stephen Howe wrote:
> Hi
>
> Is is possible to set a pointers to member function to point to an operator - implemented as a class member obviously. I suppose this hinges on whether the address operator can be applied to a class member operator.
>
> It is unusual, I have not seen it done but that does not mean it is impossible.
>
> Thanks
>
> Stephen Howe
>

The member functions like class::operator+(class) are just like any
other member functions, they just have the syntactic sugar method of
calling them. You can take their address or call them with explicit call
syntax.

Öö Tiib 12-02-2012 12:08 PM

Re: pointers to member functions - can they point to operators ?
 
On Sunday, 2 December 2012 01:03:42 UTC+2, Stephen Howe wrote:
> Hi
>
> Is is possible to set a pointers to member function to point to an operator - implemented as a class member obviously. I suppose this hinges on whether the address operator can be applied to a class member operator.


Certainly.

> It is unusual, I have not seen it done but that does not mean it is impossible.


Operators are meant to achieve most convenient syntax.
Syntax of pointers-to-member-functions on the other hand is most ugly.
It is rare case that does such sugar -> ugly switch and wins something.


All times are GMT. The time now is 11:57 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.