c++ - 抛出 std::out_of_range 异常。 "expected type-specifier"

标签 c++ exception std

我正在创建一个应该是非常差的 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/

相关文章:

c++ - 无法将参数 'double' 的 'double*' 转换为 '1' 到 'void Swap(double*, double*)'

node.js - 如何在 node.js 中处理标准输出

c++ - C++中线程安全的生产者/消费者模式

c++ - 在一个位置或更低的位置计数设置位的有效方法是什么?

c++ - NEON 向量化无符号字节乘积和 : (a[i]-int1) * (b[i]-int2)

c++ - Poco::AutoPtr 上的常量指针

c# - 用于查找被抑制异常的工具?

java - 将项目一异常(exception)纳入项目二

C# – try{}catch(Exception ex){} – 不捕获任何异常

c++ - 清除已经为空的 vector 会导致未定义的行为吗?