Hello,<br>
<br>
I can't get the following code to compile. It compiles O.K. if you REM out the second list code. Is VC++ getting confused with my names or is it a structual problem?<br>
<br>
TIA,<br>
<br>
Bob<br>
<br>
#include <iostream.h><br>
<br>
class CharList {<br>
public:<br>
char Character;<br>
char CharacterTwo;<br>
CharList *Next;<br>
secondCharacterList *secondNext;<br>
};<br>
<br>
//Input first list<br>
char GetCharacter() {<br>
char Character;<br>
<br>
cout << "What is the List 1 character?\n";<br>
cin >> Character;<br>
return Character;<br>
}<br>
<br>
char GetCharacterTwo() {<br>
char CharacterTwo;<br>
<br>
cout << "What is the List 2 character?\n";<br>
cin >> CharacterTwo;<br>
return CharacterTwo;<br>
}<br>
<br>
<br>
//Here is where the program begins<br>
void main()<br>
{<br>
int i;<br>
char Character;<br>
char CharacterTwo;<br>
<br>
//This points to the current List1 IntList item<br>
CharList *ListPtr;<br>
<br>
//This points to the last List1 IntList item created<br>
CharList *LastPtr = 0;<br>
<br>
//This points to the first List1 item in the list<br>
CharList *First = 0;<br>
<br>
//Read in characters from the user<br>
for (i=0; i<2; i++)<br>
{<br>
Character = GetCharacter();<br>
//Create a new structure to hold the character.<br>
ListPtr = new CharList;<br>
<br>
//Fill in the structures values.<br>
ListPtr->Character = Character;<br>
ListPtr->Next = 0;<br>
<br>
//If this isn't the first item created,<br>
//connect it to the list. Otherwise, it<br>
//is the start of the list.<br>
if (LastPtr)<br>
//LastPtr->Next is the Next pointer from<br>
//the last item in the list. Connect it.<br>
LastPtr->Next = ListPtr;<br>
else<br>
//If this is the first item, be sure<br>
//to save where it starts.<br>
First = ListPtr;<br>
<br>
//Set the LastPtr<br>
LastPtr = ListPtr;<br>
};<br>
<br>
// Print out<br>
if (First) {<br>
cout << "The list is ";<br>
<br>
//Now use ListPtr to traverse the list<br>
ListPtr = First;<br>
<br>
//Read through the list until Next is null<br>
do {<br>
//Print out the number<br>
cout << ListPtr->Character << " ";<br>
<br>
// Move on to the next item in the list<br>
ListPtr = ListPtr->Next;<br>
}<br>
//Stop when ListPtr is 0<br>
while (ListPtr);<br>
<br>
cout << endl;<br>
} //end of if<br>
<br>
//This points to the current List2 IntList item<br>
secondCharacterList *secondListPtr;<br>
<br>
//This points to the last List2 IntList item created<br>
secondCharacterList *secondLastPtr = 0;<br>
<br>
//This points to the first List2 item in the list<br>
secondCharacterList *secondFirst = 0;<br>
<br>
//Read in characters from the user<br>
for (i=0; i<2; i++)<br>
{<br>
CharacterTwo = GetCharacterTwo();<br>
//Create a new structure to hold the character.<br>
//ListPtr will now point to this structure.<br>
secondListPtr = new secondCharacterList;<br>
<br>
//Fill in the structures values.<br>
secondListPtr->CharacterTwo = CharacterTwo;<br>
secondListPtr->secondNext = 0;<br>
<br>
//If this isn't the first item created,<br>
//connect it to the list. Otherwise, it<br>
//is the start of the list.<br>
if (secondLastPtr)<br>
//LastPtr->Next is the Next pointer from<br>
//the last item in the list. Connect it.<br>
secondLastPtr->secondNext = secondListPtr;<br>
else<br>
//If this is the first item, be sure<br>
//to save where it starts.<br>
secondFirst = secondListPtr;<br>
<br>
//Set the LastPtr<br>
secondLastPtr = secondListPtr;<br>
};<br>
<br>
// Print out.<br>
if (secondFirst) {<br>
cout << "The list is ";<br>
<br>
//Now use ListPtr to traverse the list<br>
secondListPtr = secondFirst;<br>
<br>
//Read through the list until Next is null<br>
do {<br>
//Print out the number<br>
cout << secondListPtr->CharacterTwo << " ";<br>
<br>
//Now move on to the next item in the list<br>
secondListPtr = secondListPtr->secondNext;<br>
}<br>
//Stop when ListPtr is 0<br>
while (secondListPtr);<br>
<br>
cout << endl;<br>
} //end of if<br>
<br>
}
<br>
I can't get the following code to compile. It compiles O.K. if you REM out the second list code. Is VC++ getting confused with my names or is it a structual problem?<br>
<br>
TIA,<br>
<br>
Bob<br>
<br>
#include <iostream.h><br>
<br>
class CharList {<br>
public:<br>
char Character;<br>
char CharacterTwo;<br>
CharList *Next;<br>
secondCharacterList *secondNext;<br>
};<br>
<br>
//Input first list<br>
char GetCharacter() {<br>
char Character;<br>
<br>
cout << "What is the List 1 character?\n";<br>
cin >> Character;<br>
return Character;<br>
}<br>
<br>
char GetCharacterTwo() {<br>
char CharacterTwo;<br>
<br>
cout << "What is the List 2 character?\n";<br>
cin >> CharacterTwo;<br>
return CharacterTwo;<br>
}<br>
<br>
<br>
//Here is where the program begins<br>
void main()<br>
{<br>
int i;<br>
char Character;<br>
char CharacterTwo;<br>
<br>
//This points to the current List1 IntList item<br>
CharList *ListPtr;<br>
<br>
//This points to the last List1 IntList item created<br>
CharList *LastPtr = 0;<br>
<br>
//This points to the first List1 item in the list<br>
CharList *First = 0;<br>
<br>
//Read in characters from the user<br>
for (i=0; i<2; i++)<br>
{<br>
Character = GetCharacter();<br>
//Create a new structure to hold the character.<br>
ListPtr = new CharList;<br>
<br>
//Fill in the structures values.<br>
ListPtr->Character = Character;<br>
ListPtr->Next = 0;<br>
<br>
//If this isn't the first item created,<br>
//connect it to the list. Otherwise, it<br>
//is the start of the list.<br>
if (LastPtr)<br>
//LastPtr->Next is the Next pointer from<br>
//the last item in the list. Connect it.<br>
LastPtr->Next = ListPtr;<br>
else<br>
//If this is the first item, be sure<br>
//to save where it starts.<br>
First = ListPtr;<br>
<br>
//Set the LastPtr<br>
LastPtr = ListPtr;<br>
};<br>
<br>
// Print out<br>
if (First) {<br>
cout << "The list is ";<br>
<br>
//Now use ListPtr to traverse the list<br>
ListPtr = First;<br>
<br>
//Read through the list until Next is null<br>
do {<br>
//Print out the number<br>
cout << ListPtr->Character << " ";<br>
<br>
// Move on to the next item in the list<br>
ListPtr = ListPtr->Next;<br>
}<br>
//Stop when ListPtr is 0<br>
while (ListPtr);<br>
<br>
cout << endl;<br>
} //end of if<br>
<br>
//This points to the current List2 IntList item<br>
secondCharacterList *secondListPtr;<br>
<br>
//This points to the last List2 IntList item created<br>
secondCharacterList *secondLastPtr = 0;<br>
<br>
//This points to the first List2 item in the list<br>
secondCharacterList *secondFirst = 0;<br>
<br>
//Read in characters from the user<br>
for (i=0; i<2; i++)<br>
{<br>
CharacterTwo = GetCharacterTwo();<br>
//Create a new structure to hold the character.<br>
//ListPtr will now point to this structure.<br>
secondListPtr = new secondCharacterList;<br>
<br>
//Fill in the structures values.<br>
secondListPtr->CharacterTwo = CharacterTwo;<br>
secondListPtr->secondNext = 0;<br>
<br>
//If this isn't the first item created,<br>
//connect it to the list. Otherwise, it<br>
//is the start of the list.<br>
if (secondLastPtr)<br>
//LastPtr->Next is the Next pointer from<br>
//the last item in the list. Connect it.<br>
secondLastPtr->secondNext = secondListPtr;<br>
else<br>
//If this is the first item, be sure<br>
//to save where it starts.<br>
secondFirst = secondListPtr;<br>
<br>
//Set the LastPtr<br>
secondLastPtr = secondListPtr;<br>
};<br>
<br>
// Print out.<br>
if (secondFirst) {<br>
cout << "The list is ";<br>
<br>
//Now use ListPtr to traverse the list<br>
secondListPtr = secondFirst;<br>
<br>
//Read through the list until Next is null<br>
do {<br>
//Print out the number<br>
cout << secondListPtr->CharacterTwo << " ";<br>
<br>
//Now move on to the next item in the list<br>
secondListPtr = secondListPtr->secondNext;<br>
}<br>
//Stop when ListPtr is 0<br>
while (secondListPtr);<br>
<br>
cout << endl;<br>
} //end of if<br>
<br>
}