Latest Lists

Linked list of objects in cpp?

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; } Could help me at that part with adding an onject in the list? I don't want to it with array.I have to do it with pointer only

Public Comments

  1. void insertLast( detail aData ) { Elem<detail> *elem = new Elem<detail>( aData ); elem->next = NULL; if( NULL != this->End )this->End->next = elem; this->End = elem; }
Powered by Yahoo! Answers