2016-04-06 5 views
0

のポインタのブースト:: multi_arrayを使用しようとしています。オブジェクトのポインタの多次元配列を作成するにはboost :: multi_arrayを使いますが、コードをコンパイルしても、Eclipseで実行しようとするとプログラムは終了し、何も出力されません。 これが何らかの助けになる可能性がある場合の非常に小さな例を説明しましょう。私は次のようにこのクラスのポインタのmulti_arrayを作成して使用してみてください私は次のような問題に直面しているオブジェクト

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; 

}

ノートなどよく私は何が起こっているかのチェックを行うために、ブースト/テスト/ 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 

任意の提案を! DE[0][0]にポインタデリファレンス

+0

私は良い[C++の本](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)を読んでからポインタを使用して_notから始めるでしょう。 – sehe

答えて

1
array_type1 DE(boost::extents[2][2]); 
DE[0][0]->a=6; 

あなたは、それは事前に実際のexampleインスタンスを指す作ったことがありません。

+0

[OK]を、観察に感謝します! – user3111197