I guys, i have some questions regarding the design of my node class for a linked list or stack or whatever...
Let's show me some code, then i'll explain:
//-----------------------------------------------------------------------------
// Linked list node class
//-----------------------------------------------------------------------------
template <class T> class LinkedListNode {
public:
LinkedListNode(){prev = next = NULL;}
private:
T item;
LinkedListNode<T> *prev, *next;
public:
T GetItem(){return item;}
void SetItem(T it){item = it;}
LinkedListNode<T> *Prev(){return prev;}
LinkedListNode<T> *Next(){return next;}
};
That method is fine, but waste time in GetItem()/SetItem(), so, i could add those 2 methods, ie:
T* GetItemPtr(){return &item;}
void SetItemPtr(T *it){item = *it;}
But that's ugly, and even if i use only one set of GetItem()/SetItem(): ie replace previous code with:
T* GetItem(){return &item;}
void SetItem(T *it){item = *it;}
or
T& GetItem(){return item;}
void SetItem(T &it){item = it;}
it seem each methods has his pros and cons. What's worst is that you can't use more than one set or the compiler will cry...
Also, if the object T is not a class, but a simple variable (an int for example), it dosen't have a constructor, and im not sure if:
ZeroMemory(&item, sizeof(item));
will work on any kind of data (especially classes).
Any advice?