delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/11/25/00:18:33

From: jkolen AT typhoon DOT coginst DOT uwf DOT edu (John F. Kolen)
Subject: Re:
25 Nov 1998 00:18:33 -0800 :
Message-ID: <9811241059.ZM4189.cygnus.gnu-win32@typhoon.coginst.uwf.edu>
References: <matra AT dedalus DOT com>
Mime-Version: 1.0
To: gnu-win32 AT cygnus DOT com

/* I tried replying directly, but the mail bounced */

>   vector<vector<int> > mymatrix(n);
>   for (int i = 0;i < n;i++)
>      for (int j = 0;j < n;j++)
>         mymatrix[i][j] = 0;

What you have there should not work.  Take a look at the default constructor
and operator[] for vector<int>.

vector() : start(0), finish(0), end_of_storage(0) {}
reference operator[](size_type n) { return *(begin() + n); }
iterator begin() { return start; }

Your instantiation of of mymatrix will create n 0-element vectors with start
ptrs set to null.  This is why the deref is failing.  Here's a fix.

   for (int i = 0;i < n;i++){
      mymatrix[i].resize(n);
      for (int j = 0;j < n;j++)
         mymatrix[i][j] = 0;
   }


-- 
John F. Kolen				voice: (850)474-3075 
Assistant Professor			fax:   (850)474-3023
Dept. of Computer Science
University of West Florida
Pensacola, FL 32514
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019