c++ - Storing path from A*, using operator::new with boost::multi_array -


i'm trying use dynamic memory allocation first time. want allocate memory 2 dim dynamic array, store paths a* function. think array job boost::multi_array.

problem seem able allocate memory can't change or access of elements.

#include <iostream> #include "boost/multi_array.hpp"  typedef boost::multi_array<int, 2> array_type;  int main() {     array_type *a = new array_type;      a->resize( boost::extents[2][2] );      a[1][1] = 2;      std::cout << a[1][1] << std::endl;      delete a;      return 0; } 

compiler says:

c:\coding\code projects\c++\source files\console\main-read.cpp|14|error: no match 'operator<<' in 'std::cout << boost::multi_array_ref<t, numdims>::operator[](boost::multi_array_ref<t, numdims>::index) [with t = int; unsigned int numdims = 2u; boost::multi_array_ref<t, numdims>::reference = boost::detail::multi_array::sub_array<int, 1u>; boost::multi_array_ref<t, numdims>::index = int](1)'|. 

i have tried on ways of declaring a, can't seem find solution. appreciated.

the following solution works me. sorry confusion before.

#include <iostream> #include "boost/multi_array.hpp"  typedef boost::multi_array<int, 2> array_type;  int main() {     array_type *a = new array_type(boost::extents[2][2]);     (*a)[1][1] = 2;     std::cout << (*a)[1][1] << std::endl;     delete a;     return 0; } 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -