3

Reading the documentation of the ternary operator, I've realized that there are two special cases that I've never used:

  • you can use it with functions that return void : bool ? void : void
  • you can throw inside a ternary operator

So is the following valid, completely defined, and oftenly used (assuming that this is a class member, and the class owns a Type _data[Size]) ?

Type& at(const unsigned int i) 
{
    return (i < Size) ? (_data[i]) : (throw std::out_of_range("ERROR"));
}
4

1 回答 1

5

Size您的示例是有效且定义明确的(假设和的适当定义_data)。至于“经常使用” - 我个人以前从未见过这样的构造,因为它的价值。

于 2013-07-20T23:41:48.027 回答