"cannot convert from const Node *const to Node* Conversion loses qualifiers". I'm not sure how to fix this.
You can use const_cast, i.e.
Node * temp = const_cast<Node*>(this);
Maybe you could revise the 'constness' of the code (I did not look too closely). Perhaps read about Const correctness .
mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
Declare const Node* temp in const member functions - that's all. These functions must not modify Node fields but you can modify them via Node* temp pointer.
Yet another remark:
Did you want to implementLinked List class? If so why did you implement Node only class? A list is not a simple Node. Now you are trying to manipulate with list via Node pointers only in C (not C++ ) style. It's an example of a bad class design...
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
A type (a class) is a set of values + a set of operations. Strictly speaking, a (linked) list is not a simple collection of nodes. It's a collection of values (data) with operators:
- first (or head, or front)
- last (or tail, or back)
- count (or size)
- append (or add, or push_back)
- insert (optional)
- erase
- clear
- next
- prev (optional)
- find
- swap (optional)
- sort (optional)
and so on...
Look at http://en.wikipedia.org/wiki/Linked_lists .
Read about STL list container as an example of true class list.
As usually, a list implementation is a chained (by pointers) collection of nodes. A list node is a term for a value plus internal (as usually, invisible for list users) reference field(s) data structure.
Of course, you may define specialized class list of public nodes with exposed auxiliary next/prev fields. Remember: class list user don't want to take much trouble over these pointer fields. Moreover, it a very dangerous approach (how about unpredictable change of reference fields by wrong user code? ). It's class list member functions job.
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348