Click here to Skip to main content
15,901,122 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: rebuild problem Pin
Serge Krynine11-Mar-02 19:50
Serge Krynine11-Mar-02 19:50 
GeneralRe: rebuild problem Pin
bryce11-Mar-02 22:28
bryce11-Mar-02 22:28 
QuestionShellExecute and run WordPad.exe ?? Pin
11-Mar-02 16:43
suss11-Mar-02 16:43 
AnswerRe: ShellExecute and run WordPad.exe ?? Pin
Nish Nishant11-Mar-02 17:13
sitebuilderNish Nishant11-Mar-02 17:13 
AnswerRe: ShellExecute and run WordPad.exe ?? Pin
Lim Bio Liong11-Mar-02 17:30
Lim Bio Liong11-Mar-02 17:30 
GeneralKnown issues with MoveMemory() in XP Pin
11-Mar-02 15:52
suss11-Mar-02 15:52 
GeneralRe: Known issues with MoveMemory() in XP Pin
Tim Smith11-Mar-02 17:08
Tim Smith11-Mar-02 17:08 
GeneralCopy Assignment :: C++ Pin
valikac11-Mar-02 15:42
valikac11-Mar-02 15:42 
Hi.

I have a *pointer* to a linked list of objects. I need to write a copy assignment that will allow me to assign a new linked list the same contents as whatever the *pointer* points to.

For example:

MyList *pMList = new MyList;

pMList->insertData() // info.name1 & info.address1;
pMList->insertData() // info.name2 & info.address2;
pMList->insertData() // info.name3 & info.address3;

I would like to write a copy assignment to clone "pMList."

I have tried this:

MyList newList;

newList = *pMList;

------
const CMyList &CMyList:perator=(const CMyList &rCMyList)
{
if (&CMyList == this)
throw exception();

else
{
cloneList(CMyList);

return *this;
}
}
----------
void CMyList::cloneList(const CMyList &rSourceList)
{
cout << "\nCheck0a";

nodeCnt = rSourceList.nodeCnt;

cout << "\nCheck0b";

pOriginNode->info = rSourceList.pOriginNode->info;

CMyListNode *pNewNode = pOriginNode;

cout << "\nCheck 1";

for (CMyListNode *pTraverse = rSourceList.pOriginNode->next; pTraverse != 0; pTraverse = pTraverse->next)
{
try
{
pNewNode->next = new CMyListNode;
}

catch (bad_alloc &dmaError)
{
cerr << "\nError: " << dmaError.what[)
<< "\nPress any key to close program";

cin.ignore(256, '\n');
cin.clear();

exit(1);
}

pNewNode = pNewNode->next;
pNewNode->info = pTraverse->info;
}

cout << "\nCheck2";

pNewNode->next = 0;
}
-----

The code above looks decent. I could not find any logic error. Again, I have a *pointer* to a linked listed of objects. I need to clone that linked list. I could not get the assignment operator to work. Is there something logically incorrect?

Thanks,
Kuphryn
GeneralRe: Copy Assignment :: C++ Pin
Paul M Watt11-Mar-02 17:29
mentorPaul M Watt11-Mar-02 17:29 
GeneralRe: Copy Assignment :: C++ Pin
valikac11-Mar-02 18:51
valikac11-Mar-02 18:51 
GeneralFixed! Pin
valikac11-Mar-02 19:11
valikac11-Mar-02 19:11 
GeneralTrying to Find = in a CString Pin
11-Mar-02 14:57
suss11-Mar-02 14:57 
GeneralRe: Trying to Find = in a CString Pin
jafrazee11-Mar-02 15:53
jafrazee11-Mar-02 15:53 
GeneralRe: Trying to Find = in a CString Pin
Nish Nishant11-Mar-02 17:15
sitebuilderNish Nishant11-Mar-02 17:15 
GeneralRe: Trying to Find = in a CString Pin
12-Mar-02 0:26
suss12-Mar-02 0:26 
GeneralRe: Trying to Find = in a CString Pin
12-Mar-02 0:39
suss12-Mar-02 0:39 
Generalnebulous TRACE output Pin
moredip11-Mar-02 13:37
moredip11-Mar-02 13:37 
GeneralRe: nebulous TRACE output Pin
Shog911-Mar-02 14:07
sitebuilderShog911-Mar-02 14:07 
GeneralRe: nebulous TRACE output Pin
Roger Allen11-Mar-02 22:12
Roger Allen11-Mar-02 22:12 
GeneralRe: nebulous TRACE output Pin
moredip12-Mar-02 5:23
moredip12-Mar-02 5:23 
GeneralRe: nebulous TRACE output Pin
Stephen C. Steel12-Mar-02 11:58
Stephen C. Steel12-Mar-02 11:58 
GeneralRe: nebulous TRACE output Pin
Stephen C. Steel12-Mar-02 12:12
Stephen C. Steel12-Mar-02 12:12 
GeneralRe: nebulous TRACE output Pin
moredip12-Mar-02 12:20
moredip12-Mar-02 12:20 
Questiontoo simple to work? Pin
11-Mar-02 13:18
suss11-Mar-02 13:18 
AnswerRe: too simple to work? Pin
Joaquín M López Muñoz11-Mar-02 20:14
Joaquín M López Muñoz11-Mar-02 20:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.