1 Replies - 3591 Views - Last Post: 26 April 2010 - 09:39 PM Rate Topic: -----

#1 marvo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-April 10

pointer to vector of vectors

Posted 26 April 2010 - 09:00 PM

I declare my pointer to a vector of vectors like so:

vector< vector<int> >* adjMatrix;



Then I initialize the vector like this:

adjMatrix = new vector< vector<int> >(x, vector<int>(x, 0));



I'm having trouble accessing elements in the vector. This is what I'm currently attempting:

cout << (*adjMatrix)[0][0];



This code compiles, but when I run it, Visual Studio tells me something along the lines of "Debug Assertion Failed!" "vector subscript out of range."

Am I initializing the vector correctly? If so, am I accessing the elements correctly?

Is This A Good Question/Topic? 0
  • +

Replies To: pointer to vector of vectors

#2 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: pointer to vector of vectors

Posted 26 April 2010 - 09:39 PM

Quote

Am I initializing the vector correctly?
Yes.

Quote

If so, am I accessing the elements correctly?
No.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1