title: Solve - error C2440: 'initializing' : cannot convert from 'LinkedList *' to 'LinkedList'
body: <p>Found the solution - posted in answers.</p>
  
  <p>I get this error when I try to compile my LinkedList implementation and I cannot find where the problem lies. It points to this but I cannot find the fault.</p>
  
  <pre><code>LinkedList my =new LinkedList();
  </code></pre>
  
  <p>The class and the main function: - </p>
  
  <pre><code>struct Node {
      int data;
      Node* next;
  };
  class LinkedList {
  private:
  
      public:
          void LinkedList::init_list(struct Node *&amp;head);
          bool LinkedList::is_list_empty(struct Node *head);
          Node* LinkedList::search(struct Node *head,int value);
          int LinkedList::deleteNode(struct Node *head,int value);
          int LinkedList::deleteat(struct Node *&amp;head,int i);
          bool LinkedList::insert(struct Node *&amp;head,int value);
          bool LinkedList::insertat(struct Node *&amp;head,int value, int i);
          int LinkedList::list_length(struct Node *head);
          void LinkedList:: display(struct Node *head);
  
  };
  
  int main(){
      LinkedList my =new LinkedList();
      Node *head;
      Node *&amp;ahead = *&amp;head;
      my.init_list(ahead);
      my.display(head);
      my.insert(ahead,1111);
      //cout&lt;&lt;"1sr time";
      cout&lt;&lt; "length- " &lt;&lt;my.list_length(head)&lt;&lt;endl;
      //cout&lt;&lt; "deleting---  " &lt;&lt;deleteat(ahead,1)&lt;&lt;endl;
      my.insert(ahead,34);
      my.insert(ahead,32);
      my.insert(ahead,44);
      my.display(head);
      cout&lt;&lt;endl;
      my.insertat(ahead,4444,1);
      my.display(head);
      system("Pause");
      return 0;
  
  }
  </code></pre>
  
  <p>The complete code:- </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;exception&gt;
  
  
  using namespace std;
  
  
  
  struct Node {
      int data;
      Node* next;
  };
  class LinkedList {
  private:
  
      public:
          void LinkedList::init_list(struct Node *&amp;head);
          bool LinkedList::is_list_empty(struct Node *head);
          Node* LinkedList::search(struct Node *head,int value);
          int LinkedList::deleteNode(struct Node *head,int value);
          int LinkedList::deleteat(struct Node *&amp;head,int i);
          bool LinkedList::insert(struct Node *&amp;head,int value);
          bool LinkedList::insertat(struct Node *&amp;head,int value, int i);
          int LinkedList::list_length(struct Node *head);
          void LinkedList:: display(struct Node *head);
  
  };
  
  
  
  void LinkedList:: init_list(struct Node*&amp;head){
      head=NULL;
  }
  bool LinkedList:: is_list_empty(struct Node*head){//returns true(1) if the list is empty
      if (head==NULL){
          return true;
      }
      return false;
  }
  
  Node* LinkedList:: search(struct Node*head, int value){
      Node* pointer;
      pointer=head;
      while (pointer-&gt;next != NULL){
  
          if (pointer-&gt;data==value){
          cout&lt;&lt;"value found" &lt;&lt;endl;
          return pointer;
      }
      pointer=pointer-&gt;next;
      }
      cout&lt;&lt;"value not found!!"&lt;&lt;endl;
      return NULL;
  }
  
  int LinkedList:: deleteNode(struct Node *head, int value){
      Node* pointer;
      Node* pointer2;
      pointer=head;
      while (pointer != NULL){
          pointer2 = pointer-&gt;next;
          if(pointer2 !=NULL &amp;&amp; pointer2-&gt;data==value){
              pointer-&gt;next=pointer2-&gt;next;
              return pointer2-&gt;data;
          }
          else if(pointer2==NULL){
              cout&lt;&lt;"value not here - cannot delete";
              return NULL;
          }
          pointer=pointer-&gt;next;
      }
  }
  
  
  int LinkedList:: list_length(struct Node*head){
      int count=0;
      Node* p = head; 
      while (p != NULL) 
  { 
    ++count; 
    p = p-&gt;next; 
  }
      return count;
  }
  
  int LinkedList:: deleteat(struct Node *&amp;head, int loc){
      int i=2;
      Node*pointer =head;
      Node* pointer2;
      if(list_length(head)&lt;loc || loc&lt;1){
          cout&lt;&lt; "invalid location";
          return NULL;
      }
  
      if (loc==1){
          if(list_length(head)&gt;1){
              int val=pointer-&gt;data;
              int tempval=pointer-&gt;next-&gt;data;
              deleteat(head,2);
              pointer-&gt;data=tempval;
              return val;
          }
          else{
              head=NULL;
              return NULL;
          }
      }
  
      while (pointer-&gt;next != NULL){
  
          pointer2 = pointer-&gt;next;
          if(i==loc){                         //112 - 34 - 32 - 44
              int val = pointer2-&gt;data;
              pointer-&gt;next=pointer2-&gt;next;
              return val;
          }
          pointer=pointer2;
          i++;
      }
  }
  
  
  bool LinkedList:: insert(struct Node *&amp;head,int value)
  {
  
      //try{
          Node *q = new Node;
          q-&gt;data=value;
          q-&gt;next=NULL;
          if(head==NULL){
              head=q;
              return true;
          }
          Node *p=head;
          while(p-&gt;next!=NULL)
          {
              p=p-&gt;next;
          }
         p-&gt;next=q;
         return true;
      //}
      //catch(NullReferanceException * e ){
      //  cout&lt;&lt; "insertion was not successful" &lt;&lt;endl;
      //  return false;
      //}
  }
  
  bool LinkedList:: insertat(struct Node*&amp;head, int value,int loc){
      Node *q = new Node;     //112 - 32- 44 
      q-&gt;data=value;
      if(loc&gt;list_length(head)){
          insert(head,value);
          return true;
      }
      else if(loc&lt;=0){
          cout&lt;&lt;"invalid location";
          return false;
      }
  
      else if(loc==1){
          q-&gt;next=head;
          head=q;
          return true;
      }
      else{
          int i=1;
          Node*p =head;
          while( i&lt;loc-1){
              p=p-&gt;next;
              i++;
          }
          q-&gt;next=p-&gt;next;
          p-&gt;next=q;
          return true;
      }
  }
  
  void LinkedList:: display(struct Node *head){
      Node*p = head;
      while(p!=NULL){
          cout &lt;&lt; p-&gt;data&lt;&lt; "  ";
          p=p-&gt;next;
      }
  }
  
  int main(){
      LinkedList my =new LinkedList();
      Node *head;
      Node *&amp;ahead = *&amp;head;
      my.init_list(ahead);
      my.display(head);
      my.insert(ahead,1111);
      //cout&lt;&lt;"1sr time";
      cout&lt;&lt; "length- " &lt;&lt;my.list_length(head)&lt;&lt;endl;
      //cout&lt;&lt; "deleting---  " &lt;&lt;deleteat(ahead,1)&lt;&lt;endl;
      my.insert(ahead,34);
      my.insert(ahead,32);
      my.insert(ahead,44);
      my.display(head);
      cout&lt;&lt;endl;
      my.insertat(ahead,4444,1);
      my.display(head);
      system("Pause");
      return 0;
  
  }
  </code></pre>