Jump to content
  • Advertisement

Archived

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

Sand_Hawk

Class[X] = OtherClass;

This topic is 5741 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
Advertisement
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
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!