سؤال

I am making a class that should be a very poor string, but I have this issue with the at methods.

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];
}
هل كانت مفيدة؟

المحلول

It seems that you did not include header <stdexcept>

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top