title: Error trying to use structs in C++
body: <p>I'm trying to understeand how to use structs as lists in C++. I came up with a piece of code that to my understeanding should not result in any errors, but it did..</p>
  
  <p>My code is this:</p>
  
  <pre><code>struct item {
  int data;
  struct item *next;
  };
  
  struct item *begin = NULL;
  
  void add(int x) {
      struct item *a = new struct item();
      a-&gt;data = x;
      a-&gt;next = begin;
      begin = a;
  }
  
  int main() {
  
      add(2);
      printf("%d\n", begin-&gt;data);
  
      return 0;
  }
  </code></pre>
  
  <p>and it gives me this:</p>
  
  <pre><code>Undefined symbols for architecture x86_64:
  "operator new(unsigned long)", referenced from:
    add(int) in structtest-f49486.o
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>
  
  <p>I use GCC inside my mac terminal to run my code. I haven't seen this type of error before. I have found that the error is not present when I remove the line </p>
  
  <pre><code>struct item *a = new struct item();
  </code></pre>
  
  <p>Can anyone tell me what's wrong here?</p>
  
  <p>Thanks,</p>
  
  <p>Merijn</p>