Subject: Re:
From: [email-masked] (Benjamin Riefenstahl)

25 Nov 1998 05:35:59 -0800
Message-ID: <[email-masked]>
References: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
To: [email-masked]

Hi Ugo,

Ugo Matrangolo wrote:
> This program causes a segment violation :
> ...
>    vector<vector<int> > 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* vector<int>s and those
inner vectors are never expanded to make room for any elements (vectors
do not expand automatically). Try this one instead:

    vector<vector<int> > mymatrix(n);

    for (int i = 0;i < n;i++)
       for (int j = 0;j < n;j++)
          mymatrix[i].push_back(0); // expand the vector<int> by one

so long, benny  
======================================
Benjamin Riefenstahl ([email-masked])
Crocodial Communications EntwicklungsGmbH
Ruhrstr. 61, D-22761 Hamburg, Germany
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".