我原本以为std::tr1::array与boost::array相同,当访问超出索引范围时会抛出异常。实际上,我查看了头文件,它也是这样的。有人能解释一下为什么下面的代码在gcc版本4.0.1(Apple Inc. build 5465)上导致总线错误,而在gcc 4.1.2上导致段错误吗?
谢谢。
谢谢。
#include <exception>
#include <iostream>
#include <string>
#include <tr1/array>
#include <boost/array.hpp>
int main()
{
// boost::array<std::string, 3> arr;
std::tr1::array<std::string, 3> arr;
try
{
arr.at( 0 ) = "one";
arr.at( 1 ) = "two";
arr.at( 2 ) = "three";
arr.at( 3 ) = "nogood";
}
catch ( const std::exception& e )
{
std::cout << "exception: " << e.what() << std::endl;
}
return 0;
}