Class[X] = OtherClass;

Started by
4 comments, last by Sand_Hawk 21 years, 5 months ago
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
----------------(Inspired by Pouya)
Advertisement
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.
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]
----------------(Inspired by Pouya)
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
http://www.8ung.at/basiror/theironcross.html
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 ]
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
----------------(Inspired by Pouya)

This topic is closed to new replies.

Advertisement