[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 320
  • Last Modified:

passing by reference not updating!!!

I have the following:
CList (CRecord,CRecord&> m_Data

Then in the code I call the function

Find(&m_Data,int,double)
where Find is defined as follows
Find (CList <CRecord,CRecord&> *m_Node,int,double)
{
CList <CRecord,CRecord&> *m_S1;
m_S1 = new CList <CRecord,CRecord&> ;
when I set m_Node = m_S1; nothing happends to m_Data!!!
why is that?
}
Please make my day,
--MJ
0
maj030598
Asked:
maj030598
  • 3
  • 2
1 Solution
 
chensuCommented:
When you do
CList <CRecord,CRecord&> m_Data;

m_Data object is allocated. Its address is fixed.

When you do
Find(&m_Data,int,double);
you pass its address to the parameter m_Node.

When you do
m_Node = m_S1;
The parameter m_Node which is a pointer is changed to m_S1. m_Data won't change.
0
 
maj030598Author Commented:
so what is the solution?
if m_Node was an int, it would change.
--MJ
0
 
chensuCommented:
Once a list is created, you can call its member functions to add a node or delete a node. You may pass it using reference like this.

CList <CRecord,CRecord&> m_listData;

void ChangeData(const CList <CRecord,CRecord&> &listData)
{
    listData.AddTail(...);
    listData.SetAt(...);
    listData.RemoveAt(...);
    listData.InsertBefore(...);
}

0
 
maj030598Author Commented:
but I need its address, so I can assign it to m_S1?
0
 
chensuCommented:
CList <CRecord,CRecord&> *m_pData;


Find(&m_pData,int,double);

Find (CList <CRecord,CRecord&> **m_Node,int,double)
{
CList <CRecord,CRecord&> *m_S1;
m_S1 = new CList <CRecord,CRecord&> ;
*m_Node = m_S1;
}

0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now