|
-
September 26th, 2010, 05:01 PM
#15
Re: Call Array Member in function Help
 Originally Posted by M2W
Thanks Eri523. I'll work on your suggestions now, but will leave this post with little extra info.
The array of struct in my first post, and the linked-list in my previous post are intended to be a circular structure. That was my issue with the arrays. I needed to find a way to let the function know that it was working on the last element in the array, and then send the function call to the [0] element, and not to the next element (which would be out of bounds).
Then I tried using a linked-list. And I figured I would make it circular by connecting the last pointer to the head pointer. The problem is, I don't know how to do this connection precisely. I know the next pointer should point to the top, but I don't know how to code that. It seems like I should just add a line or two to my code on the previous post and it will work.
Finally, I want the thing to go into an endless loop, calling function_two on the next node, and then on the next one, etc. I kind of have to use recursion because that is the point of the problem assigned. The loop will end since I will put a counter that will go up with each function_two that is called and once it hits a limit it will exit the do-while.
I guess I'll worry about the memory leak once I get this thing running.
I'll go and see if I can implement what you tell me. Thanks a lot. Any more insights please post in the meantime.
To be quite frank, it looks like you are trying to take on much more than you can handle. Containers (like lists) make for good theoretical examples, but are very hard objects to code, especially if you want it done correctly.
I assume this is homework? This isn't lesson one is it? Your teacher probably gave a lesson on arrays and pointers, did you understand it? Same for function calls, by value and reference. I'd recommend you slow down and go back to those exercises...
The problem with coding with concepts you can't handle is that it always ends in "hey it compiles! and it looks like it works." Which is the worst thing you could do.
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
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
|