<div class="gmail_quote">On Fri, Aug 14, 2009 at 11:39 AM, HweeKuan Lee <span dir="ltr"><<a href="mailto:hweekuan@yahoo.com">hweekuan@yahoo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> i'm new to boost, but use the standard template library a lot. I have<br> problems with the following code.<br> <br> line 12: according to the reference, i should be able to do this, but cannot compile. compile error is very long, tell me if I should include them here.<br> <br> my compiler: gcc version 4.0.1 (Apple Inc. build 5490)<br> <br> thanks in advance for your help.<br> <br> �1 #include <boost/multi_array.hpp><br> �2<br> �3 int main ( ) {<br> �4<br> �5 � typedef boost::multi_array<double,2> matrix_type;<br> �6 � typedef matrix_type::iterator � � � �iterator;<br> �7<br> �8 � matrix_type mat(boost::extents[2][3]);<br> �9 � double v = .2;<br> �10<br> �11 � for(iterator it=mat.begin();it!=mat.end();++it) {<br> �12 � � (*it) = v; // compile error<br> �13 � }<br> �14 }</blockquote></div><br>Your iterator dereferences to a slice through your 2-d array. To initialise all<br>the 6 double elements of mat you need to nest another loop.<br><br>#include <boost/multi_array.hpp><br> <br>int main ( )<br>{<br><br>� typedef boost::multi_array<double,2> matrix_type;<br>� typedef matrix_type::iterator������� iterator;<br><br>� matrix_type mat(boost::extents[2][3]);<br>� double v = .2;<br><br>� for(iterator it=mat.begin();it!=mat.end();++it)<br> � {<br>��� for(int i=0;i!=3;++i)<br>����� (*it)[i] = v;<br>� }<br>}<br><br>- Rob.<br>