如何生成C++定义调用的动态生成
How to generate Dynamic generation of C++ define calls
我在 Cpp 代码中使用整数值进行了定义。我需要循环调用它们。我该怎么做?
// Defines:
#define A0 0
#define A1 1
#define A2 2
// ...
#define A50 50
// Now based on loop I need to call these defines
for (int i = 0; i <= 50; i++){
function_name(A<i>, value);
}
#define
宏仅在调用编译器之前由预处理器计算。因此,预处理器宏在运行时不存在,并且不能由使用仅在运行时知道值的变量构建的名称来引用。
对于您正在尝试的内容,您必须使用数组,例如:
#define A0 0
#define A1 1
#define A2 2
...
#define A50 50
const int A[51] = {A0, A1, A2, ..., A50};
...
for (int i = 0; i <= 50; i++){
function_name(A[i], value);
}
相关文章:
- 动态调用具有不同返回类型的相同命名函数
- 有没有办法在 c++ 中按函数的名称动态调用函数
- 获取要在C++中动态调用的回调函数的地址
- 如何在没有动态调用的情况下确定子节点的类型
- C++ CPP 使用参数动态调用 DLL
- 用CPP中的参数动态调用外部DLL
- 动态调用成员方法c++
- 我们能否从运行时给出的参数中检测出要动态调用的函数
- 动态调用C++(成员)函数
- 通过指针操作动态调用的数组
- 当子项目动态调用库时,如何将两个子项目与主项目静态链接
- 你能从DLL中动态调用一个对象吗
- c++中处理函数的动态调用
- 在不知道函数签名的情况下动态调用函数
- 在linux中,与动态调用相关的时钟周期中程序的意外执行时间
- 动态调用dll
- 如何在c++中动态调用属性名,就像JS中的方括号符号一样
- 生成c/c++程序运行时的动态调用图
- 如何从C++动态调用汇编函数
- 是什么使编译器从第一个示例中的动态调用更改为第二个示例中的静态调用?