gpt4 book ai didi

c++ - 宏 C++ #define Examples(obje) (::f(s, (obje), arg1, arg2, arg3))

转载 作者:行者123 更新时间:2023-12-02 05:02:50 25 4
gpt4 key购买 nike

我在 C++ 中有这个特殊的宏函数:

你能向我解释一下它是如何工作的吗:

#define EXAMPLE(obje) (::f(s, (obje), arg1, arg2, arg3))

我有几个问题:

1) ::f 是什么意思?编译器在哪里搜索函数f

2) (obje) 是什么意思?为什么是在括号之间?

最佳答案

::f(...) - 调用函数 f 仅搜索全局范围(避免依赖于参数的查找)。 (假设 f 是一个函数)。

(obje) - obje 带有括号。取决于 object 是什么。典型的宏技巧,以避免 obje 在宏展开时产生奇怪的效果。

关于c++ - 宏 C++ #define Examples(obje) (::f(s, (obje), arg1, arg2, arg3)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58818821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com