First I just wanted to say thanks for all the help everyone has provided for me before. I'm sure you wanted to reach through the internet and strangle me :) .

I having some difficulty with understanding/implementing a linked list class with another class. Just something as simple as interacting with each class has me puzzled. Say I have a class called race car. This class contains the make, number, team and driver of the race car. Then say there is a race track class. This class will define a linked list for the race car class. The member functions might do a bunch of things like add, swap, delete and print. I'm not concerned with the member functions. Would something like this work:

class racecar {

      private:
          string make, team, driver;
          int number;
.
.
.
.
};
class raceTrack {
typedef racecar* ListItemType;

      private:
          racecar make, team, number;
          struct ListNode
	   {
	      ListItemType item;
	      ListNode    *next;
	   }; 
.
.
.
};

This is just an example I thought of. Could someone help me by using this example or show a different example? Thanks.

Sorry, I fixed the typo. I am working on an assignment and templates can't be used. Also I would like to add that the example is not my assignment.

In that case, I think it's fine. Just try to explain to me please what is line:
racecar make, team, class, number;
Why are you making instances of racecar class?

Well class should not be in there. I thought I would have to make an instance so I could add a race car to the linked list.

No, not about class keyword now :)
But what is make, team and number?
You use them as instances of class racecar, and I fail to see why do you need that.

But yet again, maybe it's my fault.

Well class should not be in there. I thought I would have to make an instance so I could add a race car to the linked list.

Yeah.. You can do that... You just declare the List and the class (for eg. Class car) as usual. The only thing special is that the ListItemType is car.

class Car
{
	private:
		string name;
		string team;
		stringdriver;
		int plate_number;

	public:
		..........
};

class List
{
	private:
		struct ListN
		{
			Car item;
			ListN* next;
		};

		ListN* head;
		ListN* tail;
		int size;

	public:
		...........
}

Help on linked list implementation can be found here. ;)

This article has been dead for over six months. Start a new discussion instead.