我正在创建一个应该是非常差的 string
的类,但是我在 at
方法中遇到了这个问题。
MyString.h
char at(unsigned int i) const throw(std::out_of_range);
char& at(unsigned int i) throw(std::out_of_range);
MyString.cpp
char MyString::at(unsigned int i) const throw(std::out_of_range) {
if (mylength_ == 0 || i < 0 || i > mylength_ - 1)
throw std::out_of_range("nopenope");
return string_[i];
}
char& MyString::at(unsigned int i) throw(std::out_of_range) {
if (mylength_ == 0 || i < 0 || i > mylength_ - 1)
throw std::out_of_range("nopenope");
return string_[i];
}
最佳答案
您似乎没有包含 header <stdexcept>
关于c++ - 抛出 std::out_of_range 异常。 "expected type-specifier",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22442355/