c++ - C++中的函数名宏

标签 c++ macros

我有一个看起来像这样的 C++ 宏

#define lua_tpushstring(L,n,f) \
            (lua_pushstring(L, n), lua_pushstring(L, f))

我想修改它让它像这样工作

#define lua_tpush(TYPE,L,n,f) \
            (lua_pushstring(L, n), lua_pushTYPE(L, f))

lua_tpush(boolean, L, "a", true);
lua_tpush(string, L, "a", "");

什么是简单的改变?

最佳答案

Token concatenation :

#define lua_tpush(TYPE,L,n,f)  (lua_pushstring(L, n), lua_push##TYPE(L, f))

关于c++ - C++中的函数名宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6909566/

相关文章:

c++ - 在 Android NDK 中使用 "sp"

c++ - 由于奇怪的 "compiler generated file could not be created"错误,QT5.6.2 构建无法正常工作

c++ - gnuplot 输出生成 png C++ Xcode

c - 检测宏中的整数常量表达式

c - 如何在跨文件预处理时获取唯一值

c - 宏依赖宏

c++ - 为特定 ID 搜索结构 vector 的有效方法?

C++:free():下一个大小无效(快速)

c - 为什么这个 If 语句即使在条件为假时也会执行?

macros - 在运行时调用 macroexpand