title: Storing Pointer to sqlite3 Database inside class throws segfault
body: <p>In my program, I am using a sqlite3 database. </p>
  
  <p>In order to handle the Ctrl-C signal and gracefully terminate the program by closing the database and closing all Midi ports (my program uses RtMidi), I need to set up a global object that stores them. I have made a class:</p>
  
  <pre><code>class Config {
  private:
      sqlite3 *Database;
      RtMidiIn *MidiIn;
      RtMidiOut *MidiOut;
  
  public:     
      sqlite3 *getDatabase();
      void setDatabase(sqlite3 *mDatabase);
  
      RtMidiIn *getMidiInStream();
      void setMidiInStream(RtMidiIn *mMidiIn);
  
      RtMidiOut *getMidiOutStream();
      void setMidiOutStream(RtMidiOut *mMidiOut);
  
      Config();
      ~Config();
  };
  </code></pre>
  
  <p>The constructor:</p>
  
  <pre><code>Config::Config() {
      //open the midi i/o ports (irrelevant to the problem at hand)
      sqlite3 *mDatabase = this-&gt;Database;
      if (sqlite3_open(FILE_DATABASE, &amp;mDatabase)) {
          puts(ERROR_MESSAGE_DATABASE_OPEN_FAIL);
          puts(sqlite3_errmsg(this-&gt;Database));
      }
      puts(NOTE_MESSAGE_DATABASE_OPEN);
  }
  </code></pre>
  
  <p>However, the <code>sqlite3_open()</code> and <code>sqlite3_close()</code> functions are giving me segfaults when i try to call them on <code>mConfig-&gt;getDatabase()</code>.</p>
  
  <p>I tried making the fields public and passing <code>mConfig-&gt;Database</code> and that changes nothing. How can I store the database inside the Config class?</p>
  
  <p>--------EDIT:
  I forgot to include the get/set database functions:</p>
  
  <pre><code>sqlite3 *Config::getDatabase() { return this-&gt;Database; }
  
  void Config::setDatabase(sqlite3 *mDatabase) { this-&gt;Database = mDatabase; }
  </code></pre>