Solved

passing by reference not updating!!!

Posted on 1998-08-02
5
304 Views
Last Modified: 2013-11-19
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
Comment
Question by:maj030598
  • 3
  • 2
5 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1320138
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
 

Author Comment

by:maj030598
ID: 1320139
so what is the solution?
if m_Node was an int, it would change.
--MJ
0
 
LVL 23

Expert Comment

by:chensu
ID: 1320140
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
 

Author Comment

by:maj030598
ID: 1320141
but I need its address, so I can assign it to m_S1?
0
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 1320142
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Expand macro to include alternate header placement and naming 5 75
Perl Awk Need Help 3 128
Excel Use VBA to get user's Mac Address for their computer 5 244
Window placement 17 87
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question