title: How does shared_ptr work in c++ without initialization
body: <p>I was going through shared_ptr and came across this.</p>
  
  <pre><code>class A
  {
      public:
          A() { cout &lt;&lt; "In constructor" &lt;&lt; endl; }
          ~A() { cout &lt;&lt; "Destructor" &lt;&lt; endl; }
          void fun() { cout &lt;&lt; "In fun... " &lt;&lt; endl; }
  };
  int main()
  {
      shared_ptr&lt;A&gt; a;
      a-&gt;fun();
      return 0;
  }
  </code></pre>
  
  <p>The output of this is - In fun...</p>
  
  <p>I would like to understand how is this giving above output.</p>
  
  <p>On further experimentation if there is a member variable and being used in this function it throws an SIGSEGV.</p>
  
  <pre><code>class A
  {
      public:
          A() { cout &lt;&lt; "In constructor" &lt;&lt; endl; }
          ~A() { cout &lt;&lt; "Destructor" &lt;&lt; endl; }
          void fun() { a = 5 ; cout &lt;&lt; "In fun... " &lt;&lt; endl; }
          int a;
  };
  
  int main()
  {
      // A::fun();
      shared_ptr&lt;A&gt; a;
      a-&gt;fun();
      return 0;
  }
  </code></pre>
  
  <p>Above throws SIGSEGV stating <strong>this</strong> pointer is null.</p>