正在尝试使用对象指针的boost::multi_array
Trying to use boost::multi_array of pointer of object
我面临以下问题。我想使用boost::multi_array创建一个对象的多维指针数组,但即使我编写的代码是编译的,当我尝试在Eclipse中运行时,程序也会终止,并且不会打印任何内容。让我举一个很小的例子,以防这有任何帮助。因此拥有以下非常小的简单类:
class example {
public:
example();
virtual ~example();
int a;
};
我只是尝试以以下方式创建并使用这个类的指针数组:
int main() {
typedef boost::multi_array<example * , 2> array_type1;
array_type1 DE(boost::extents[2][2]);
DE[0][0]->a=6;
DE[1][0]->a=7;
DE[0][1]->a=8;
DE[1][1]->a=9;
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
还要注意,当我使用boost/test/minimal.hpp运行相同的代码时(http://www.boost.org/doc/libs/1_46_1/libs/test/doc/html/minimal.html)为了检查正在发生的事情,结果主要看起来是这样的:
int test_main(int, char*[]){
typedef boost::multi_array<example * , 2> array_type1;
array_type1 DE(boost::extents[2][2]);
DE[0][0]->a=6;
DE[1][0]->a=7;
DE[0][1]->a=8;
DE[1][1]->a=9;
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return boost::exit_success;
}
我收到以下消息:
/usr/include/boost/test/minimal.hpp(123): exception "memory access violation at address: 0x00000008: no mapping at fault address" caught in function: 'int main(int, char**)'
**** Testing aborted.
**** 1 error detected
任何关于如何解决这个问题的建议现在都会对我很有帮助!
array_type1 DE(boost::extents[2][2]);
DE[0][0]->a=6;
您在DE[0][0]
处取消引用指针,但事先从未使其指向实际的example
实例。
相关文章:
- 理解boost::asio-async_read在无需读取内容时的行为
- boost::进程间消息队列引发错误
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- cmake如何在fedora工作站中找到boost静态库包
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- Boost Graph Library,修复节点大小
- 什么是"#include <boost/functional/hash.hpp> "?
- 基于boost的程序的静态链接——zlib问题
- C++:如何在CLion IDE中安装Boost
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- 如何在boost beast http请求中设置http头
- Boost Spirit,获取迭代器内部语义动作
- boost::asio::steady_timer()与sleep()我应该使用哪一个
- boost::asio如何生成多个协同程序,然后加入它们
- boost beast Websocket Multi Request Server/Client 并不是真正的 mul
- 如何使用 std::get 作为 boost-multi-index 容器键的global_fun
- 编译boost时"threading=multi"究竟做了什么
- Boost Multi Index标识索引
- Boost Multi Index:基于列表内容的索引
- Boost Multi-Index中的多个索引查询