ok i try to write a linked list of objects from one class
here is the the class:
class detail{
int code;
string unit;
string name;
float price;
public:
detail(int c, string u, string n, float p);
int get_code(){return code;};
string get_unit(){return unit;};
string get_name(){return name;};
float get_price(){return price;};
};
detail::detail(int c, string u, string n, float p){
cout << "Enter code:";
cin >> code;
cout << "Enter unit:";
cin >> unit;
cout << "Enter name:";
cin >> name;
cout << "Enter price:";
cin >> price;
};
And here is the linked list:
template <class T>
struct Element {
?????; //here i must to put a pointer to an object from class detail
Element<T>* next; //pointer to next element
};
template <class T>
class List {
private:
Elem<T>* Begin;
Elem<T>* End;
public:
List();
~List();
void insertLast(detail aData);
void print() const;
void removeAt(unsigned aPos);
};
template <class T>
List<T>:: List() {
Begin = Current = NULL;
}
template <class T>
void List<T>:: insertLast(T aData) {
if(!Begin) {
insertFirst(aData);
return;
}
Current->next = new Elem<T>;
Current = Current->next;
Current->data = aData;
Current->next = NULL;
}
Could help me at that part with adding an onject in the list?
I don't want to do it with array.I have to do it with pointers only!
InsertLast have to put an element in the last position ,but what i have to do to put an object from class detail in the list?