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