Solved

passing by reference not updating!!!

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

910 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

20 Experts available now in Live!

Get 1:1 Help Now