Throwing out of range exception in C++

前端 未结 1 1918
心在旅途
心在旅途 2020-12-29 22:01

This code works;

int at(int index) {
  if(index < 1 || index >= size)
    throw 0;

  return x[index];
}

Yet this doesn\'t



        
相关标签:
1条回答
  • 2020-12-29 22:17

    Replace throw std::out_of_range; with throw std::out_of_range ("blah");. I.e. you need to create an object, you cannot throw a type.

    0 讨论(0)
提交回复
热议问题