Link to home
Start Free TrialLog in
Avatar of maj030598
maj030598

asked on

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
Avatar of chensu
chensu
Flag of Canada image

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.
Avatar of maj030598
maj030598

ASKER

so what is the solution?
if m_Node was an int, it would change.
--MJ
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(...);
}

but I need its address, so I can assign it to m_S1?
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial