title: 0xC0000005: Access violation reading location 0x00000004
body: <p>My problem is that I am facing error <strong>"Unhandled exception at 0x00bd3364 in qualnet.exe: 0xC0000005: Access violation reading location 0x00000004."</strong>.</p>
  
  <p>The scenario is that I have defined a struct (NodesInfoTable) which is used in another struct (Node). Please note that I am using this code in a network simulator QualNet. I am getting error whenever I execute my code in the network simulator. However, if I execute my code in a separate project (test project) consisting of only this code, then this code executes correctly. </p>
  
  <p>I think that there is some problem with memory allocation. But I wonder why it is running correctly in one project but not in another.</p>
  
  <p>I also searched other post with similar title, but their problem is different. This is why, I used new post for my inquiry.</p>
  
  <p>My code is provided below:</p>
  
  <p>file: node.h</p>
  
  <pre><code>struct NodesInfoTable {
      int nodeId;
      int nodeStatus;
      list&lt;int&gt; channels;
  };
  
  
  struct Cluster {
      int clusterId;
      list&lt;int&gt; commonChannels;
      Cluster() {
          clusterId= -1;
      }
  };
  
  
  
  struct Node {
      int var1;
      int var2;
      Cluster* cluster;
      list&lt;NodesInfoTable*&gt; nodeTable;
  };
  </code></pre>
  
  <p>file: node.cpp</p>
  
  <pre><code>Node* newNode;
  newNode = (Node*) MEM_malloc(sizeof(Node));
  .....
  newNode-&gt;cluster = new Cluster();
  newNode-&gt;nbTable = ??
  ....
  </code></pre>
  
  <p>file: myfile.cpp</p>
  
  <pre><code>NodesInfoTable nbTable1; 
  nbTable1.nodeId = 1;
  nbTable1.nodeStatus = 2;
  node-&gt;nbTable.push_back(nbTable1); //'node' object is available here
  </code></pre>
  
  <p>I am getting error:</p>
  
  <blockquote>
    <p>Unhandled exception at 0x00bd3364 in qualnet.exe: 0xC0000005: Access violation reading location 0x00000004.</p>
  </blockquote>
  
  <p>on line:</p>
  
  <blockquote>
    <p>node->nbTable.push_back(nbTable1);</p>
  </blockquote>
  
  <p>And the debugger navigate me to the code <code>_Nodeptr _Newnode = _Buynode(_Pnode, _Prevnode(_Pnode), _Val);</code> in file: list. Some more statements above and below this code are also mentioned below:</p>
  
  <pre><code>_Nodeptr _Pnode = _Where._Mynode();
  _Nodeptr _Newnode = _Buynode(_Pnode, _Prevnode(_Pnode), _Val);
  _Incsize(1);
  _Prevnode(_Pnode) = _Newnode;
  _Nextnode(_Prevnode(_Newnode)) = _Newnode;
  </code></pre>
  
  <p>Please not that I am correctly accessing 'cluster' object through 'node' object. However, the problem is with 'nbTable'. Since I have used statement <code>newNode-&gt;cluster = new Cluster()</code>, I think that this is why, memory is allocated to this object. But I dont have idea that how should I handle <code>newNode-&gt;nbTable = ??</code> because I think that it is the problem.</p>
  
  <p>Thank you in advance and I look forward towards the solution.</p>