为什么将宏参数放在括号中会导致错误
Why putting a macros argument in parentheses leads to an error?
关于c++中的预处理器指令,我有一个非常有趣的问题。
考虑以下宏及其用法:
#define FUNCTION(a, b) void (a)(int ¤t, int candidate)
{
if ((current b candidate) == false){ // Marked Line
current = candidate;
}
}
FUNCTION(minimum, <)
FUNCTION(maximum, >)
我的问题是,为什么用以下代码行更改"标记行"甚至无法编译:
... if ((current (b) candidate) == false) ...
因为'<'是一个二进制运算符,如果两边都没有操作数,则无法对其求值。您可以在没有宏的情况下验证这一点,只需尝试编译以下代码:
bool LessThan( int a, int b )
{
return( a (<) b );
}
至少您应该看到"预期的表达式"或类似的错误。
相关文章:
- 如何通过参数抛出错误消息
- 我收到同义重复编译器错误。我应该如何修复"类型"X"的参数与类型"X"的参数不兼容?
- 错误 没有与参数列表匹配的重载函数"getline"实例
- 为什么 std::绑定错误参数可以成功?
- 在函数中使用 const int size 参数创建数组会在 Visual Studio 中抛出错误 C++:表达式的计
- g++ 为 transform() 的参数生成错误
- 如何在C++中使用 Void 而不会收到有关参数的错误
- 错误:参数中无效地使用了无效表达式
- xgboost 构建错误:参数包未扩展为"..":
- src/caffe/parallel.cpp:70:1:错误:“参数”未命名类型
- OpenCV 错误:ERClassifierNM1 中的错误参数
- 为什么显示错误:参数太少而无法正常工作
- 算法错误:参数无法从对中掩盖 1
- 类模板方法的专用化,类型名称是类模板 - 错误:参数处的类型/值不匹配
- C++连接函数错误-参数无效
- 错误:参数无效
- (自适应)opencv中的阈值错误(cvarrToMat中的错误参数(未知数组类型))
- OpenCV错误:cvGetSize中的错误参数(数组应该是CvMat或IplImage)
- OpenCV 2.2:未知函数中的错误参数,文件.. .ocv OpenCV modulescoresr
- 错误:参数声明的存储类说明符无效