title: Exception thrown: read access violation. **this** was nullptr. occurred
body: <p>I am a novice at C++. I have started writing a rather large code on a project and I want to make a good base for that. I get the following error when running in Visual Studio:</p>
  
  <p>Exception thrown: read access violation. <strong>this</strong> was nullptr. occurred</p>
  
  <p>After searching similar questions, I could not find the solution for my code. The error is occurring in Driver.cpp at:
  m_setup->SetEquation(...)</p>
  
  <p>Any help is really appreciated. I also appreciate if you have suggestion to improve my code structure.</p>
  
  <p>Main.h:</p>
  
  <pre><code>#ifndef FEM_AD1D_MAIN_H
  #define FEM_AD1D_MAIN_H
  
  namespace FEM_AD1D
  {
      class Driver;
      Driver* m_driver;
  }
  #endif
  </code></pre>
  
  <p>Main.cpp:</p>
  
  <pre><code>#include "Main.h"
  #include "Driver.h"
  
  #include &lt;iostream&gt;
  
  using namespace FEM_AD1D;
  
  
  int main()
  {
      std::cout &lt;&lt; "Hello World!\n";
  
      m_driver-&gt;Run();
  }
  </code></pre>
  
  <p>Driver.h:</p>
  
  <pre><code>#ifndef FEM_AD1D_DRIVER_H
  #define FEM_AD1D_DRIVER_H
  
  namespace FEM_AD1D
  {
      class Setup;
  
      class Driver
      {
      public:
  
          Driver(Setup* setup);
  
          void Run();
          void PreProc();
  
      private:
  
          Setup* m_setup;
  
          const int m_nDim = 1;
          const double m_aCoef = 1.0;
          const double m_bCoef = 3.0;
          const double m_cCoef = 0.0;
          const double m_fCoef = 1.0;
  
          const double m_xMin = 0.0;
          const double m_xMax = 1.0;
  
          const int m_nElem = 5;
          const int m_elemType = 2;
          const double m_meshStretch = 0.0;
  
          const int m_nGaussPoint = 3;
      };
  }
  #endif
  </code></pre>
  
  <p>Driver.cpp:</p>
  
  <pre><code>#include "Driver.h"
  #include "Setup.h"
  
  #include &lt;iostream&gt;
  #include &lt;array&gt;
  
  using namespace FEM_AD1D;
  
  
  Driver::Driver(Setup* setup)
  {
      m_setup = setup;
      //m_setup = new Setup();
  }
  
  
  void Driver::Run()
  {
      PreProc();
  }
  
  void Driver::PreProc()
  {
      std::cout &lt;&lt; "Hello World 2!\n";
      m_setup-&gt;SetEquation(m_nDim, m_aCoef, m_bCoef, m_cCoef, m_fCoef);
  }
  </code></pre>
  
  <p>Setup.h:</p>
  
  <pre><code>#ifndef FEM_AD1D_SETUP_H
  #define FEM_AD1D_SETUP_H
  
  #include &lt;vector&gt;
  
  namespace FEM_AD1D
  
  {
      class Setup
      {
      public:
  
          Setup();
  
          void SetEquation(int nDim, double aCoef, double bCoef, double cCoef, double fCoef);
  
      private:
  
          int m_nDim;
          double m_aCoef;
          double m_bCoef;
          double m_cCoef;
          double m_fCoef;
      };
  }
  #endif
  </code></pre>
  
  <p>Setup.cpp:</p>
  
  <pre><code>#include "Setup.h"
  #include "Driver.h"
  
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  using namespace FEM_AD1D;
  
  Setup::Setup() :
      m_nDim(0),
      m_aCoef(0.0),
      m_bCoef(0.0),
      m_cCoef(0.0),
      m_fCoef(0.0)
  {
  }
  
  void Setup::SetEquation(int nDim, double aCoef, double bCoef, double cCoef, double fCoef)
  {
      // Set the coefficients of the equation 
      std::cout &lt;&lt; "Hello World 3!\n";
      m_nDim = nDim;
      m_aCoef = aCoef;
      m_bCoef = bCoef;
      m_cCoef = cCoef;
      m_fCoef = fCoef;
  }
  </code></pre>