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:
int iRetVal;
CycleCountOrder* cycleOrder = NULL;
CycleCountLineItem* cycleLine = NULL;
iRetVal = m_CycleCount.GetCCOrderLine(pOneLocation.szOrderNum[c], cycleOrder, cycleLine);
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:
header file
int GetCCOrderLine(CString szOrderLnitem, CycleCountOrder* cycleOrder, CycleCountLineItem* cycleCountLine);
cpp file
int CCycleCount::GetCCOrderLine(CString szOrderLnitem, CycleCountOrder* cycleOrder, CycleCountLineItem* cycleCountLine)
{
CString szCurrOrderLnitem;
for(int c = 0; c < m_Orders.GetCount(); c++)
{
CycleCountOrder* currentOrder = m_Orders[c];
for(int d = 0; d < currentOrder->m_LineItems.GetCount(); d++)
{
CycleCountLineItem* currentLine = currentOrder->m_LineItems[d];
szCurrOrderLnitem.Format("%s-%d-%d", currentOrder->szOrderNum, currentLine->nLnitemNum, currentLine->nSubitemNum);
if(szCurrOrderLnitem == szOrderLnitem)
{
cycleOrder = currentOrder;
cycleCountLine = currentLine;
return FUNC_OK;
}
}
}
return FUNC_ERROR;
}
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:
CArray<CycleCountOrder*, CycleCountOrder*> m_Orders;
CArray<CycleCountLineItem*, CycleCountLineItem*> m_LineItems;