Archived

This topic is now archived and is closed to further replies.

Class[X] = OtherClass;

This topic is 5527 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here I am again with more questions. I have 2 classes, a CLinked and a CNode. CNode contains the data and CLinked holds the list. I changed an certain item in CNode and want to put it back in CLinked. How can I do this:
CLinked[Index] = CNode;
 
I CLinked I have the [] operator overloaded and in CNode the = operator. Can I now use the above code or will it fail and how I can get it straight? Sand Hawk ---------------- -Earth is 98% full. Please delete anybody you can.
My Site

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I have two things to say...

Sand_Hawk: <b>I CLinked I have the [] operator overloaded and in CNode the = operator. Can I now use the above code or will it fail and how I can get it straight?</b>

First to answer your question, assuming you overloaded operator[] to return a mutable reference to a CNode then it should work.

Second, why are you writing your own container when you could use std::list<>? Not understanding it isn''t an excuse.

Share this post


Link to post
Share on other sites
Well, I should take a look into the STL, however, I need to write my own linked list class for school. And probably I will use this one instead of the STL in my games. Anyway, writing your own Linked List is as important as knowing/understanding STL.

[EDIT]
Whoops, I didn't read the reply complete well. It should return a MUTABLE reference. So CNode& . And when there is nothing to return, just return NULL.
[/EDIT]

Sand Hawk

----------------
-Earth is 98% full. Please delete anybody you can.


My Site


[edited by - sand_hawk on October 23, 2002 3:38:48 PM]

Share this post


Link to post
Share on other sites
erm you create extra classes to create linked lists?
oh god
just create a classname *next;
classname *prev; pointer set it to NULL in your constructor and create a function that add a passed class to your list
i hate these template classes for linked lists in my opinion they are a waste of memory

Share this post


Link to post
Share on other sites
quote:
Original post by Basiror
i hate these template classes for linked lists in my opinion they are a waste of memory

Your opinion is misguided as templated linked lists hardly use any memory.



[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]

Share this post


Link to post
Share on other sites
Basiror, I use a classed because it was specified in the assignment. i have my almost finished the templated version. Templates are good since you write it only once, instead of the C way, where you have to write for each type a new list.

Sand Hawk

----------------
-Earth is 98% full. Please delete anybody you can.


My Site

Share this post


Link to post
Share on other sites