title: Function that returns a pointer to const 2-d array (C++)
body: <p>I'm an intermittent programmer and seem to have forgotten a lot of basics recently.</p>
  
  <p>I've created a class <code>SimPars</code> to hold several two-dimensional arrays; the one shown below is <code>demPMFs</code>. I'm going to pass a pointer to an instance of <code>SimPars</code> to other classes, and I want these classes to be able to read the arrays using <code>SimPars</code> accessor functions. Speed and memory are important.</p>
  
  <p>I know life is often simpler with vectors, but in this case, I'd really like to stick to arrays.</p>
  
  <p><strong>How do I write the accessor functions for the arrays?</strong> If I'm interested in the nth array index, how would I access it using the returned pointer? (Should I write a separate accessor function for a particular index of the array?)  What's below is certainly wrong. </p>
  
  <pre><code>// SimPars.h
  #ifndef SIMPARS_H
  #define SIMPARS_H
  #include "Parameters.h" // includes array size information
  
  class SimPars {
   public:
    SimPars( void );
    ~SimPars( void );
  
    const double [][ INIT_NUM_AGE_CATS ] get_demPMFs() const;
  
   private:
     double demPMFs[ NUM_SOCIODEM_FILES ][ INIT_NUM_AGE_CATS ];
  
  };
  #endif
  
  
  // SimPars.cpp
  SimPars::SimPars() {
   demPMFs[ NUM_SOCIODEM_FILES ][ INIT_NUM_AGE_CATS ];
   // ...code snipped--demPMFs gets initialized...
  }
  
  //...destructor snipped
  const double [][ INIT_NUM_AGE_CATS ] SimPars::get_demPMFs( void ) const {
    return demPMFs; 
  }
  </code></pre>
  
  <p>I would greatly appreciate some kind of explanation with proposed solutions.</p>