pointers to member functions - can they point to operators ?

S

Stephen Howe

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

W Karas

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 +); }
 
R

Richard Damon

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::eek:perator+(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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top