c++ - Trying to use boost::multi_array of pointer of object -


i face following problem. want create multidimensional array of pointers of object use boost::multi_array, though code write compiles, when try run in eclipse program terminated , nothing printed. let me illustrate little example in case of help. having following small simple class:

class example {      public:             example();             virtual ~example();              int a;  }; 

i try create , use multi_array of pointers of class in following way:

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; 

}

note when run same code using boost/test/minimal.hpp (http://www.boost.org/doc/libs/1_46_1/libs/test/doc/html/minimal.html) check of going on , result main looks this:

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; 

}

i receive following message:

/usr/include/boost/test/minimal.hpp(123): exception "memory access violation @ address: 0x00000008: no mapping @ fault address" caught in function: 'int main(int, char**)'  **** testing aborted. **** 1 error detected 

any suggestions on how resolve helpful me right now!

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

you dereference pointer @ de[0][0], never made point actual example instance beforehand.


Comments