所以我有一个函数需要一个函数指针作为输入,它的原型(prototype)是这样的:
int function(int (*op)(int, int));
我想知道是否可以为该函数指针传递一个运算符。特别是这个内置运算符:
int operator|(int, int);
我已经试过了:
function(&(operator|));
得到了这样的错误:
error: no matching function for call to 'function(<unresolved overloaded function type>)'
我已经试过了:
function(&(operator|(int, int)));
得到了这样的错误:
error: expected primary-expression before 'int'
我在文档中查找过这种情况,但我得到的是关于“地址”运算符 (operator&) 的信息,而不是关于运算符地址的信息....
编辑:
见上一个问题 Calling primitive operator-functions explicitly in C++
最佳答案
内置运算符 |需要两个 int
并返回一个 int
不能通过符号 operator|
访问。例如,以下不编译
int a = operator|(2,3);
关于c++ - C++中运算符的函数指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17299933/