Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ Pointer problem
    text
    copied!<p>I'm having a pointer problem that I can't seem to figure out. It seems like I've used pointers in this way a 1000 times so I'm not quite sure what is going on here. I have the following code:</p> <pre><code>int iRetVal; CycleCountOrder* cycleOrder = NULL; CycleCountLineItem* cycleLine = NULL; iRetVal = m_CycleCount.GetCCOrderLine(pOneLocation.szOrderNum[c], cycleOrder, cycleLine); </code></pre> <p>Whenever I call GetCCOrderLine I step inside the function and it assigns valid values to the pointers cycleOrder and cycleLine. When I step outside of the function GetCCOrderLine the references are NULL again. The code below is how the GetCCOrderLine is defined:</p> <p>header file</p> <pre><code>int GetCCOrderLine(CString szOrderLnitem, CycleCountOrder* cycleOrder, CycleCountLineItem* cycleCountLine); </code></pre> <p>cpp file</p> <pre><code>int CCycleCount::GetCCOrderLine(CString szOrderLnitem, CycleCountOrder* cycleOrder, CycleCountLineItem* cycleCountLine) { CString szCurrOrderLnitem; for(int c = 0; c &lt; m_Orders.GetCount(); c++) { CycleCountOrder* currentOrder = m_Orders[c]; for(int d = 0; d &lt; currentOrder-&gt;m_LineItems.GetCount(); d++) { CycleCountLineItem* currentLine = currentOrder-&gt;m_LineItems[d]; szCurrOrderLnitem.Format("%s-%d-%d", currentOrder-&gt;szOrderNum, currentLine-&gt;nLnitemNum, currentLine-&gt;nSubitemNum); if(szCurrOrderLnitem == szOrderLnitem) { cycleOrder = currentOrder; cycleCountLine = currentLine; return FUNC_OK; } } } return FUNC_ERROR; } </code></pre> <p>Also the two arrays that are being accessed in the above code and that are being used to assign values to the pointers passed in are declared as follows. Also these arrays are filled with objects created with the new operator:</p> <pre><code>CArray&lt;CycleCountOrder*, CycleCountOrder*&gt; m_Orders; CArray&lt;CycleCountLineItem*, CycleCountLineItem*&gt; m_LineItems; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload