-
April 28th, 2009, 04:45 PM
#1
problem with function.....
where have I gone wrong.....just a beginer here...something is wrong with my remove function.
struct TeleType{
string name;
string phoneNo;
TeleType *ptr;
};
void remove(TeleType *);
const int REC = 5;
int main(){
TeleType client[REC] = {{ "Summer One", "(876)876-8765", &client[1] },
{ "Joe Smoe", "(726)245-8954", &client[2] },
{ "Mighty Moe", "(927)569-2592", &client[3] },
{ "Slow Joe", "(812)294-0283", &client[4] },
{ "Winter Two", "(846)764-3467", &client[0] }};
for(int i = 0; i < REC; i++)
cout << setw(20) << left << client[i].name
<< setw(10) << client[i].phoneNo << " "
<< setw(10) << client[i].ptr
<< endl;
cin.ignore(1);
return 0;
}
void remove(TeleType *ptr)
{
*myPtr = client[0]; // I can't get this to delete client[1](Joe Smoe) yet keep
myPtr.ptr = &client[2]; // the loop going in the cout statement.
delete client[1];
return;
}
-
April 28th, 2009, 04:50 PM
#2
Re: problem with function.....
There's a lot wrong there......
1) You posted code without code tags.
2) You're trying to use "delete" in the remove function, when (as far as I can tell) the linked list is currently being allocated on the stack. Which is itself pretty strange.
3) You have indexes hard-coded in the remove function for some mysterious reason.
4) You have not given a sufficient explanation of your goal, difficulty, and specific problem encountered.
-
April 28th, 2009, 05:09 PM
#3
Re: problem with function.....
sorry about that...I've been playing with this for the last week and am getting frustated. I have changed my remove function several times, some with less errors this is what I have now.
error C2065: 'myPtr' : undeclared identifier
(39) : error C2065: 'client' : undeclared identifier
(40) : error C2065: 'myPtr' : undeclared identifier
(40) : error C2228: left of '.ptr' must have class/struct/union
type is ''unknown-type''
(40) : error C2065: 'client' : undeclared identifier
error C2065: 'client' : undeclared identifier
-
April 28th, 2009, 05:14 PM
#4
Re: problem with function.....
assignment calls for me to remove one of the structures from the linked list...catch is that I need to take the value of the ptr in the removed structure and replace it with the value of the preceding structure. I believe I would have to delete that structure after doing this.
-
April 28th, 2009, 08:29 PM
#5
Re: problem with function.....
error C2065: 'myPtr' : undeclared identifier
(39) : error C2065: 'client' : undeclared identifier
(40) : error C2065: 'myPtr' : undeclared identifier
(40) : error C2228: left of '.ptr' must have class/struct/union
type is ''unknown-type''
(40) : error C2065: 'client' : undeclared identifier
error C2065: 'client' : undeclared identifier
Errors talk to you. Listen.
(39) : error C2065: 'client' : undeclared identifier - you didn't declared variable client
(40) : error C2065: 'myPtr' : undeclared identifier - you didn't declared variable myPtr
(40) : error C2228: left of '.ptr' must have class/struct/union - you have used pointer. Use -> instead of . ( or variable isn't declared so linker cannot resolve the member of variable )
(40) : error C2065: 'client' : undeclared identifier - you didn't declared variable client
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|