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.

You don't need to write your own list!
Lists in c++

And "class" is reserved c++ keyword, you can't use it as varable named class!

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.

updated #5

Try to write it, and see will it work :)

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. ;)

Great. Thanks for the help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.