From mboxrd@z Thu Jan 1 00:00:00 1970 From: Benjamin Riefenstahl To: gnu-win32@cygnus.com Subject: Re: Date: Tue, 24 Nov 1998 16:45:00 -0000 Message-id: <365B2255.53AA7E02@crocodial.de> References: <199811232132.WAA00238@dedalus.com> X-SW-Source: 1998-11/msg00920.html Hi Ugo, Ugo Matrangolo wrote: > This program causes a segment violation : > ... > vector > mymatrix(n); > > for (int i = 0;i < n;i++) > for (int j = 0;j < n;j++) > mymatrix[i][j] = 0; > ... > Can anyone tell me if it is a bug or my fault ? Your fault ;-) The declaration allocates a vector of n *empty* vectors and those inner vectors are never expanded to make room for any elements (vectors do not expand automatically). Try this one instead: vector > mymatrix(n); for (int i = 0;i < n;i++) for (int j = 0;j < n;j++) mymatrix[i].push_back(0); // expand the vector by one so long, benny ====================================== Benjamin Riefenstahl (benny@crocodial.de) Crocodial Communications EntwicklungsGmbH Ruhrstr. 61, D-22761 Hamburg, Germany - For help on using this list (especially unsubscribing), send a message to "gnu-win32-request@cygnus.com" with one line of text: "help".