如何为operator[]
和迭代器启用绑定检查?
You can activate runtime iterator and bounds checking by compiling with -D_GLIBCXX_DEBUG
. Also note that random-access containers provide the always bounds-checking at()
-operation in addition to operator []
.
References:
GCC STL debug mode: http://gcc.gnu.org/onlinedocs/libstdc++/manual/debug_mode_using.html#debug_mode.using.mode
at() operation: std::vector::at()
, std::deque::at()
and std::array::at()
you should overload the operator[]
for your specific classes. If you want to use an existing STL container, the at()
function is a bounds-checked version of the operator[].
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.