本文介绍了我的钳宏的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我的钳宏,当我的价值超过10,我的高度超过17它停止工作。任何想法?

I have a problem with my clamp macro, when when my value is over 10 and my high is over 17 it stops working. Any idea?

#define CLAMP(value, low, high) (((value)<(low))?(low):(((value)>(high))?(high):(value)))


推荐答案

我建议使用比宏更安全的方式:

I would suggest using a safer way than a macro:

template <typename T> T CLAMP(const T& value, const T& low, const T& high)
{
  return value < low ? low : (value > high ? high : value);
}

这篇关于我的钳宏的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-16 16:21
查看更多