title: Adding random numbers into a linked-list using loop
body: <p>I want to add a completely random number into a linked-list, but instead of having all of my code in main, I want to use the object-oriented approach. I have my standard Node class and it's header, and then in main I want a loop that runs through 20 times and then stops adding more. I was given my insert function and how it would be called in main, but I can't seem to get the random numbers to work. I understand that you can't assign an int to a class, but I don't really know how else to incorporate my random number into my function in order to insert it into my list. </p>
  
  <p>Here is my code. Observe the error on line 20 of main. Any insight would be great. Thanks!</p>
  
  <p>Main.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;time.h&gt;
  #include "Node.h"
  
  using namespace std;
  
  int main()
  {
      srand(time(NULL));
  
      Node link_head;
      Node instance;
  
      for (int i = 0; i &lt; 20; i++)
      {
          int random = rand() % 100;
  
          instance.insert(&amp;link_head, &amp;random);
      }
  }
  </code></pre>
  
  <p>Node.h</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  
  #ifndef NODE_H
  #define NODE_H
  
  typedef int ElementType;
  
  class Node
  {
  public:
  
      Node();
      ElementType data;
      Node *next;
      int insert(Node *, Node *);
  
  };
  
  #endif NODE_H
  </code></pre>
  
  <p>Node.cpp</p>
  
  <pre><code>#include &lt;iomanip&gt;
  #include &lt;iostream&gt;
  #include "Node.h"
  
  using namespace std;
  
  Node::Node()
  {
      this -&gt; data = 0;
      this -&gt; next = NULL;
  }
  
  int Node::insert(Node *link_head, Node *newNode)
  {
          Node *current = link_head;
  
          while (true) 
          { 
              if(current-&gt;next == NULL)
              {
                  current-&gt;next = newNode;
                  break;
              }
              current = current-&gt;next;
          }
  
      return 0;
  }
  </code></pre>