我有这个代码:
class A {
public:
bool has_foo() { return true; }
};
int main() {
A a;
CALL(a, foo);
}
我想通过宏扩展调用方法has_foo
:
#define CALL(object, method) do { object.has_ ## method ## (); } while(0)
上面的代码在 MSVC 上编译,但在 GCC 上失败。
我想使用宏扩展以避免运行时开销。
最佳答案
试试
#define CALL(object, method) do { object.has_##method(); } while(0)
关于c++ - 通过宏展开调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54444414/