Solved

passing by reference not updating!!!

Posted on 1998-08-02
5
296 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now