Im stuck on a probably beginners error.
They gave us the unlink function as Item* DList::unlink(Item* ptr) so thats what i put there but then when is use unlink(this) in the destructor it gives the following error:S?
Hopefully someone can help me on this beginners mistake but im already stuck on this one for ages...
Error:
error C2664: 'unlink' : cannot convert parameter 1 from 'Item *const ' to 'const char *
Destructor:
Item::~Item()
{
unlink(this);
// TODO: remove this item from the list it's in
}
Hard to tell without your full program, but I can suggest one or two things. First of all, this is a CONSTANT pointer. so your function Item* DList::unlink(Item* ptr) should be Item* DList::unlink(const Item* ptr).
.
And you can't do ptr = NULL; //constant, remember?
#ifndef _DLIST_H_INCLUDED
#define _DLIST_H_INCLUDED
// Taks Double Linked List
// Your name: ___________ your name _________________________
//
// The following declaration is necessary to be able
// to declare '_dlist' as a 'DList *' before the Class Dlist
// has actually been defined
class DList;
// The Item class
// This class will serve as a base class for ALL type of items
// that will ever be added to a DList.
// It defines basic functionality
class Item
{
public:
// constructor
//destructor definition
// note: function bodies still have to be implemented!
Item(void);
~Item(void);
virtualvoid print(); // why is this one declared as virtual ?? Think about it!!
// define additional member function here
protected:
int _id; // The id of the item.
private:
Item* _prev;
Item* _next;
DList* _dlist;
friendclass DList;
};
// The DList class
// This class defines basic functionality that one would
// expect from a double linked list.
class DList
{
public:
DList(void);
~DList(void);
// define additional member function here
void destroy_list();
void print();
virtual Item* create();
virtual Item* append();
virtual Item* insert();
virtual Item* find(int id);
Item* unlink(Item* ptr);
int delete_item(int id);
private:
Item* _top_of_ring;
int _id_counter;
};
#endif