[TriLUG] OT: C++ question, linked list of objects
Joseph Mack NA3T
jmack at wm7d.net
Mon Apr 3 09:21:16 EDT 2006
On Sun, 2 Apr 2006, Barry Gaskins wrote:
> Well the linked list object needs to be able to get and set the next
> pointer of the node object.
these have to be private (part of the homework spec) so I'll
need accessors/mutators (getters/setters - apparently
everyone has different names for these functions).
> If this is a more advanced class (which I doubt since you
> are asking such basic questions), then you could make the
> next member of the node class private but declare the
> linkedList class to be a friend class of the node class so
> that I can access the private next member of the node
> class.
I knew methods could be friends. I didn't know that classes
could be friends.
> You can see an example of doing this here:
> http://cis.stvincent.edu/swd/lists/lists.html
on reading this I see my abstraction is wrong. Currently my
node in the list is a submarine and there is a
submarine->next. I should have my node as an object of some
generic Node class (with attributes data and next, just like
it was holding data of type int) but instead the data be the
submarine object. This looks cleaner - in this case there
would be no next in the submarine.
Haven't seen the dummy first node version before. I've been
handling the first node as a special case.
> And example of just making the next member of the node
> public can be found here:
> http://www.codeproject.com/cpp/Lists_and_Trees.asp
better not do this.
> If I were you I would start out with the simpler way of
> doing it with the next member of the node class as a
> public member. Then after you have everything working
> correctly if you have the time and want to get extra
> credit then you can try to do the harder example of making
> the next member of the node object private.
have already been told that all node
attributes/data/whatever have to be private.
Thanks Joe
--
Joseph Mack NA3T EME(B,D), FM05lw North Carolina
jmack (at) wm7d (dot) net - azimuthal equidistant map
generator at http://www.wm7d.net/azproj.shtml
Homepage http://www.austintek.com/ It's GNU/Linux!
More information about the TriLUG
mailing list