Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function Pointer of an Operator in C++

So I have a function that expects a function pointer as an input and whose prototype goes something like this:

int function(int (*op)(int, int));

I was wondering if I can pass an operator in for that function pointer. Specifically this built in operator:

int operator|(int, int);

I've tried this:

function(&(operator|));

and got this kind of error:

error: no matching function for call to 'function(<unresolved overloaded function type>)'

I've tried this:

function(&(operator|(int, int)));

and got this kind of error:

error: expected primary-expression before 'int'

I've looked for this situation in documentation, but I get things about the "address of" operator (operator&) instead of things about the address of an operator....

Edit:

See previous question Calling primitive operator-functions explicitly in C++

like image 681
Ned Bingham Avatar asked Jun 25 '13 14:06

Ned Bingham


1 Answers

The built-in operator | that takes two int and returns an int can not be accessed through the notation operator|. For instance, the following does not compile

int a = operator|(2,3);
like image 74
Johan Råde Avatar answered Sep 28 '22 09:09

Johan Råde