![]() |
Linked List Of Objects
Hi,
I need to be able to hold a linked list of pointers to objects of a class I made myself. I know to add to a linked list something like this: :
//constructionJust wondering what I replace the (int *data) part with? Cheers |
replace the int with the data type you are wanting to save to your linked list ? not quite sure if get what you mean. are all the objects of the same type ?
|
Sorry for not explaining myself very well.
I have a class Vehicle so in my code I have a line like... :
So that's what I want to store in the linkedlist, the myVeh pointer. NOt sure what I would replace int with. |
void addToList(Vehicle *data); ?
I'm assuming that the current implementation you are using are storing pointers to integer values ? void addToList( new Vehicle(...) ); or just pass the addToList myVeh. |
oooh Dawei, I saw that post before you removed it ;)
|
LOL. It was a virtual duplicate, including the time stamp.
|
Quote:
|
That is what I thought was very unsure though.
I tried it and now I get this Error: error C2664: 'Node::setData' : cannot convert parameter 1 from 'Vehicle *' to 'int *' The code around the error location is... :
Any idea? |
yeah, you haven't changed the node to take a pointer to a Vehicle. You will need to change whatever it is in your Node class that is int * to Vehicle *.
At current you are trying to set a Pointer of an Integer type to a pointer of a Vehicle type. If you are still stuck, show me your Node class and I'll show you where. |
Hi, thanks a lot for your replies, tried a few things but can't seem to get it right.
here's my code list.h... :
#include "vehicle.h"list.cpp :
I've tried changing all the 'int' to 'Vehicle' but as yet have had no joy. To recap, I'm trying to use this code given to us by our lecturer so that the linked list will contain pointers to objects of the Vehicle class. Anyone have any ideas? Oh, and does anyone know what's missing from the deleteCurrent() function? Thanks in advanced |
| All times are GMT -5. The time now is 2:07 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC