如何为 operator[]
和迭代器启用边界检查?
最佳答案
您可以通过使用 -D_GLIBCXX_DEBUG
编译来激活运行时迭代器和边界检查。另请注意,除了 operator []
之外,随机访问容器还提供始终检查边界的 at()
操作。
引用资料:
GCC STL Debug模式: http://gcc.gnu.org/onlinedocs/libstdc++/manual/debug_mode_using.html#debug_mode.using.mode
at() 操作:std::vector::at()
, std::deque::at()
和 std::array::at()
https://stackoverflow.com/questions/5594686/