Throw and ternary operator in C++

后端 未结 4 1379
盖世英雄少女心
盖世英雄少女心 2020-12-03 22:19

The following code compiles with G++ 4.6.1, but not with Visual Studio 2008

return (m_something == 0) ? 
    throw std::logic_error(\"Something wrong happene         


        
4条回答
  •  Happy的楠姐
    2020-12-03 22:46

    It is standard C++. Either (or both) of the then/else expressions in a conditional expression is allowed to be a throw-expression instead (C++98 5.16/2).

    If Visual Studio crashes when compiling it... that would seem to be unfortunate!

提交回复
热议问题