title: c++ write data with cyclic dependencies in binary file using flatbuffers
body: <p>I'm trying to write a Graph into a binary file by using flatbuffers. A graph consists of nodes and edges. Every node has at least one edge and every edge consists of two nodes.</p>
  
  <p>Excerpt from MyGraph.fbs:</p>
  
  <pre><code>namespace MyGraph;
  
  table Node {
    edges:[Edge];
  }
  
  table Edge {
    startNode:Node;
    endNode:Node;
  }
  
  table Graph {
    allNodes:[Node];
  }
  
  root_type Graph;
  </code></pre>
  
  <p>Now I want to create a simple graph and write it into a bytefile:</p>
  
  <pre><code>FlatBufferBuilder fbb;
  // create first node
  auto node1mloc = DG::CreateNode(fbb, 0, 0);
  
  // create second node
  auto node2mloc = DG::CreateNode(fbb, 0, 0);
  
  // create edge between first and second node
  auto edgeloc = DG::CreateEdge(fbb, node1mloc, node2mloc);
  
  
  // ???
  // store the edge in the edges-vector of node1 and node2
  // ???
  
  // store nodes in graph
  flatbuffers::Offset&lt;Node&gt; nodes[] = {node1mloc, node2mloc};
  
  auto allNodes = fbb.CreateVector(nodes, 2);
  
  auto graphloc = DG::CreateGraph(fbb, allNodes);
  
  DG::FinishGraphBuffer(fbb, graphloc);
  
  
  // write graph into file
  auto buffer_pointer = fbb.GetBufferPointer();
  SaveFile("myfile2.bin", reinterpret_cast&lt;const char *&gt;(buffer_pointer), fbb.GetSize(), true);
  
  
  
  // load graph from file
  string binData;
  LoadFile("myfile2.bin", true, &amp;binData);
  
  auto graph = DG::GetGraph(binData.data());
  cout &lt;&lt; graph-&gt;allNodes()-&gt;size() &lt;&lt; endl;
  assert(graph-&gt;allNodes()-&gt;size() == 2);
  </code></pre>
  
  <p>The Problem is, that after creating the nodes, I can't add the edge to the edges-vector of node1 and node2. Is there a solution for that kind of cyclic dependencies between two types.</p>