class - C++ Classes - What is wrong with my program? -


insert method appends item end of linked list.

can't figure out how code case node null, , want add it.

struct node{        int data;        node *next;         node(int data):data(data),next(null){}         void insert(int data){             if (this==null){                this=new node(data); // compiler complaining here.                                     // how go setting value of (which presently null) new node?             }        } } 

you can not assign value this pointer special keyword , should point valid block of memory. looking @ usage, trying mean this:

void insert(int data){             if (!next){                next = new node(data);              } 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

javascript - Preserving URL fragment through CAS sign-on -

asp.net mvc - Implementing normal user/pass, Twitter & Facebook auth -