类型的宏定义不起作用

man*_*tta 0 c++

为什么以下代码不起作用?

// Template function definition
template <typename T>
void apply(const T& input);

// Helper macro definition
#define APPLY_FUNCTION(PIXELTYPE) \
  apply<##PIXELTYPE>(input);

// Use macro to call function
APPLY_FUNCTION(uint8_t);
Run Code Online (Sandbox Code Playgroud)

这会产生以下错误:

错误:粘贴"<"和"uint8_t"不会提供有效的预处理令牌

Bar*_*rry 8

##是为了一起粘贴代币.你不需要那样,所以只需:

#define APPLY_FUNCTION(PIXELTYPE) apply<PIXELTYPE>(input);
Run Code Online (Sandbox Code Playgroud)

那就是两条准则:

  1. 不要结束您的宏;需要用户添加它将节省您的一些错误.
  2. 请不要写这个宏.