C++ vector of objects: assigning the objects -


I have to create a hex board for the class and I have a problem with my code nodes for the board in my graph There are 2D vectors of each node in the vector of neighboring nodes. I can not specify neighboring nodes in the vector.

Node class:

  class node {public: string hex_type = "E"; // To start vector blank & lt; Node & gt; Neighbors; Int xcordinate; Int Ycoordinate; Classroom Graph {Public: Integer Size; Graph () {it-> Size = 11; } Article (int a) {it-> Size = A; } Vector & lt; Vector & lt; Node & gt; & Gt; Nodes; Zero start () {int x, y; Int max = it-> Size-1; This- & gt; Nodes = vector & lt; Vector & lt; Node & gt; & Gt; (Shape, vector & lt; node & gt; (shape)); (X = 0; x & lt; size; ++ x) {for (y = 0; y  nodes [x] [y] = node (); It-> nodes [x] [y] .xchordinate = x; this-> nodes [x] [y] ycoordinate = y; this-> nodes [x] [y] .neighbors = Vector & nt; node & gt; (6); if ((x == 0) & amp; amp; y = = 0) {this-> nodes [x] [y] lemon [0] = this -> nodes [x + 1] [y];}}}}};  

My print statement here produces only a series of numbers: -842150451

  cout ; this-> nodes [0] [0] .neighbors [0] .xcoordinate;  

< Div class = "post-text" itemprop = "text">

when it-> nodes [x] [y] .ne Ighbors [0] = this-> nodes [x + 1] [y]; Excuted, x = 0, y = 0. nodes [1] [0] is not initalized You can first intimate all the nodes. For / p>

  (x = 0; x  ++ x) {for (y = 0; y & lt; size; ++ y) {// it-> nodes [X] [y] = node (); it-> nodes [x] [y] .xchordinate = x; this-> nodes [x] [y]. Ycoordinate = y; }} For (x = 0; x  nodes [x] [y] Lemon [0] = est- & gt; Nodes [x + 1] [y]; }}}  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -