hi I am trying to create a linked list class. My problem is the "this" pointer. See, because the member functions cannot refer to the immediate variable instance by name, I must use the "this" pointer. Look at it so far, with only one member function complete:
Code:class LinkedList { public: int AddTo ( LinkedList *head ) { this = new LinkedList; //<-- ERROR: NON-LVALUE IN ASSIGNMENT if( !this ) return 0; if( !head ) { head = this; head->prev = 0; head->next = 0; return 1; } LinkedList *b = head; int nodeCount = 1; while( b->next ) { b = b->next; nodeCount++; } b->next = this; this->prev = b; return nodeCount; } LinkedList *prev; LinkedList *next; };
I have tried everything, but it just will not compile.
Can anyone give me some direction?



LinkBack URL
About LinkBacks


