我正在制作一个非常差的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];
}
答案 0 :(得分:1)
您似乎没有包含标题<stdexcept>