带有C ++宏的可选参数 [英] Optional Parameters with C++ Macros
问题描述
有什么方法获得可选参数与C ++宏?
Is there some way of getting optional parameters with C++ Macros? Some sort of overloading would be nice too.
推荐答案
C ++宏没有从C改变。因为C没有重载和函数的默认参数,它肯定没有他们的宏。所以回答你的问题:不,这些功能不存在宏。您唯一的选择是使用不同的名称定义多个宏(或根本不使用宏)。
C++ macros haven't changed from C. Since C didn't have overloading and default arguments for functions, it certainly didn't have them for macros. So to answer your question: no, those features don't exist for macros. Your only option is to define multiple macros with different names (or not use macros at all).
作为侧注:在C ++中,宏尽可能多。如果您需要这样的功能,就有可能过度使用宏。
As a sidenote: In C++ it's generally considered good practice to move away from macros as much as possible. If you need features like this, there's a good chance you're overusing macros.
这篇关于带有C ++宏的可选参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!