Hey, I'm having some issues with pointers. I've got two linked list classes, one is a list of arguments and one is a list of orders. I'm trying to integrate the two together, but it's not quite working.
What I want to do is pass a pointer to my function, and end up having my pointer point to the root of the argument list of the specified order. But, it just crashs when I try to get data out of it. It works if I preset the data for a non-pointer, which makes me think it's just not copying correctly. Unfortunantly I've never been to great with pointers -,-.
Here's what I think the issue is, I'll post the whole code at the bottom;
Argument list code:Code:#include <iostream.h> int main() { AiStack a; ArgList arg; ArgList *args; arg.NewArg(18); a.NewOrder(10000, arg); cout << a.GetNextOrder(args) << endl; cout << arg.GetNextArg(); //works fine cout << args->GetNextArg(); //crashs here } int AiStack::GetNextOrder(ArgList *Args) { int a = 0; OrderNode *copy; OrderNode *xerox; copy = root; while(a != TravOrders) { a++; if(root->next != 0) { root = root->next; } else { return 0; } } xerox = root; root = copy; TravOrders++; Args = &xerox->Args; //This should make Args point to the adress of xerox->args right? return xerox->Order; }
Order List code:Code:#include <windows.h> struct ArgNode { int Arg; ArgNode *next; }; class ArgList { protected: int TravArgs; int Args; ArgNode *root; public: ArgList() {Args = 0, TravArgs = 1, root = new ArgNode, root->next = 0;} void NewArg(int arg); int GetLastArg(); int GetNextArg(); int GetNumberOfArgs() {return Args;} }; void ArgList::NewArg(int arg) { ArgNode *copy; copy = root; while(root->next != 0) root = root->next; root->next = new ArgNode; root = root->next; root->Arg = arg; root->next = 0; root = copy; Args++; } int ArgList::GetLastArg() { ArgNode *copy; ArgNode *xerox; copy = root; while(root->next != 0) root = root->next; xerox = root; root = copy; return xerox->Arg; } int ArgList::GetNextArg() { int a; ArgNode *copy; ArgNode *xerox; copy = root; while(a != TravArgs) { a++; if(root->next != 0) { root = root->next; } else { return 0; } } xerox = root; root = copy; return xerox->Arg; }
Also, my compiler is spouting this, which doesnt make sence to me. (The value is assigned to a pointer, so it shoulden't care if it's not used in a function, right? And why is it saying it's never used?)Code:#include "Arg.h" struct OrderNode { int Order; ArgList Args; OrderNode *next; }; class AiStack { protected: int TravOrders; int Orders; OrderNode *root; public: AiStack() {Orders = 0, TravOrders = 1, root = new OrderNode, root->next = 0;} void NewOrder(int order, ArgList Args); int GetLastOrder(ArgList *Args); int GetNextOrder(ArgList *Args); int GetNumberOfOrders() {return Orders;} }; void AiStack::NewOrder(int order, ArgList Args) { OrderNode *copy; copy = root; while(root->next != 0) root = root->next; root->next = new OrderNode; root = root->next; root->Order = order; root->Args = Args; root->next = 0; root = copy; Orders++; } int AiStack::GetLastOrder(ArgList *Args) { OrderNode *copy; OrderNode *xerox; copy = root; while(root->next != 0) root = root->next; xerox = root; root = copy; Args = &xerox->Args; return xerox->Order; } int AiStack::GetNextOrder(ArgList *Args) { int a = 0; OrderNode *copy; OrderNode *xerox; copy = root; while(a != TravOrders) { a++; if(root->next != 0) { root = root->next; } else { return 0; } } xerox = root; root = copy; TravOrders++; Args = &xerox->Args; return xerox->Order; }
Code:Parameter 'Args' is never used in function AiStack::GetNextOrder(ArgList *) 'Args' is assigned a value that is never used in function AiStack::GetNextOrder(ArgList *)
Well thank you for any help, I've been stuck with this problem for a few days now.



LinkBack URL
About LinkBacks




.