If been trying to use the STL list with my own class, to make up nodes.
In other words, what I am trying to do is that instead of just pushing in just an integer or a character for example, I want to be able to push in my own object, for example a coordinate with two int variables in it. Here is the code:
This is the node:
And now my main:
Coordinate( int, int );
Coordinate::Coordinate( int value1, int value2 )
yvalue = value1;
zvalue = value2;
My question is: how do I reference each individual member of the coordinate. Can I do just [cout << *iter->yvalue;] ?
using namespace std;
list< Coordinate > myGrid;
list< Coordinate >::iterator iter;
Coordinate *newPtr1 = new Coordinate( 0, 1 );
Coordinate *newPtr2 = new Coordinate( 0, 2 );
Coordinate *newPtr3 = new Coordinate( 1, 1 );
myGrid.push_back( newPtr1 );
myGrid.push_back( newPtr2 );
myGrid.push_back( newPtr3 );
iter = myGrid.begin();
Or, do I need to create the necesary functions inside the coordinate class to return the desired data?
So far every example and tutorial that I have seen deals only with lists and simple data types like ints and strings. But none that I have seen with user defined types. If I could use the stl list it would facilitate so much for me.