warning C4715: 'compare' : not all control pathsreturn a value

来源:互联网 发布:光通讯网络交换机 编辑:程序博客网 时间:2024/06/18 07:18
template <typename T, typenameL>
int compare( const T& strA, constL& strB )
{
    stringstr_A(strA), str_B(strB); //用C风格的数组构造string对象
    try
    {
      if( str_A > str_B )
         return 1;
      else if ( str_A == str_B )
         return 0;
      else
         return -1;
    }
   catch(exception ex)
    {
      cout << "compareexception!" << endl;
    }
    return 0;
}

如果省略最后那个返回语句,则在“出现异常跳过条件判断则无返回,使catch块代码执行单其没有返回语句”
种情况下会没有返回值,故会出现warning C4715: 'compare' : not all control pathsreturn a value错误。所以最后一个返回语句不能省。