title: c++ assigning value to struct member through shared pointer causes SIGSEGV
body: <p>Good day.  I'm refreshing my C++ knowledge after not using it since the late 90s and am getting up-to-speed on new things.  Today, my question is on shared pointers and structs.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>#include &lt;memory&gt;
  
  struct A {
      int x;
  };
  
  int main() {
    shared_ptr&lt;struct A&gt; y;
    y-&gt;x =0;
  
    return 0;
  }
  </code></pre>
  
  <p>compile string:</p>
  
  <pre><code>g++ -Wall -Wpedantic --std=gnu++11 -g test.cpp -o test
  </code></pre>
  
  <p>valgrind memcheck notes there's an "Invalid write of size 4" on line 11, which is y->x = 0</p>
  
  <p>So, my question is: why is there an invalid write?  My understanding--obviously faulty--is that the shared_ptr idiom will handle allocation and de-allocation of memory for the thing it's pointed to, and indeed this happens when I use it to point to primitive types and classes as far as I can tell, but this case of using it with a struct is tripping me up.</p>
  
  <p>The real use case I'm trying to figure out is using a smart pointer to store a struct sockaddr_in, but I figure I should (re)learn to crawl before I learn to build smart pointers to objects defined in a time before smart pointers were a widely-accepted thing.</p>
  
  <p>Thanks.</p>