为什么在一个判断中常量一般都是写在比较运算符前面?
例如:template<class _Pr2>
void unique(_Pr2 _Pred)
{ // erase each element satisfying _Pred with previous
if (2 <= _Mysize)/////////////////////////////////////////////////////here
{ // worth doing
iterator _First = begin();
iterator _After = _First;
for (++_After; _After != end(); )
if (_Pred(*_First, *_After))
_After = erase(_After);
else
_First = _After++;
}
}
还有常见的
if(IDOK==dialog.DoModal())//here
{
  ......
}

解决方案 »

  1.   

    那是因为IDOK=dialog.DoModal(),编译器会报错
    而dialog.DoModal()=IDOK编译器不会报错
    所以为了养成良好的编程风格,建议常量写前面
      

  2.   

    if (2 <= _Mysize)/////////////////////////////////////////////////////据我所知,写成这样是为了避免:
    原本意思是:if(x==2)
    错误的写为:if()x=2),不会报错如果常量写在比较运算符前面
    原本意思是:if(2==x)
    错误的写为:if()2=x),会报错