要注意这样,x或y中的一个将被重新评估。 how about:#define max(x,y) ( ((x)>(y)) ? (x) : (y) ) beware that this way one of x or y will be re-evaluated. 如何 : #def ine max(x,y)(((x)>(y))? (x):( y)) 要注意这样,x或y中的一个将被重新评估。 how about: #define max(x,y) ( ((x)>(y)) ? (x) : (y) ) beware that this way one of x or y will be re-evaluated. 什么''错误的: 模板< typename T> const T& max(const T& x,const T& y) { 返回x< y? y:x; } ?? Stefan - Stefan Naewe naewe.s_AT_atlas_DOT_de What''s wrong with: template<typename T>const T& max(const T& x, const T& y){return x<y ? y : x;}??Stefan --Stefan Naewenaewe.s_AT_atlas_DOT_de 怎么样 : #define max(x,y)(((x)>(y))?(x):( y)) 要注意这样一个将重新评估x或y。 how about: #define max(x,y) ( ((x)>(y)) ? (x) : (y) ) beware that this way one of x or y will be re-evaluated. 有什么问题: 模板< typename T> const T& max(const T& x,const T& y) {返回x< y? y:x; } What''s wrong with: template<typename T> const T& max(const T& x, const T& y) { return x<y ? y : x; } 出了什么问题: #include< algorithm> 使用std :: max; What''s wrong with: #include <algorithm>using std::max; 这篇关于胜林的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-03 15:34